Zelda Classic Coverage Report


Directory: src/
File: src/zc/script_drawing.cpp
Date: 2022-12-14 07:01:52
Exec Total Coverage
Lines: 553 4816 11.5%
Functions: 25 104 24.0%
Branches: 236 2676 8.8%

Line Branch Exec Source
1 // This program is free software; you can redistribute it and/or modify it under the terms of the
2 // modified version 3 of the GNU General Public License. See License.txt for details.
3
4 //! ritate_sprite_trans doesn't seem to be supported by or allegro header !?
5
6 //glibc 2.28 and later require this: -Z
7 #ifdef __GNUG__
8 #define ALLEGRO_NO_FIX_ALIASES
9 #endif
10
11 #define LOG_BMPBLIT_LEVEL 0
12 #include "precompiled.h" //always first
13
14 #include "base/allegro_wrapper.h"
15 #include "script_drawing.h"
16 14 #include "rendertarget.h"
17 #include "maps.h"
18 #include "tiles.h"
19 #include "zelda.h"
20 #include "ffscript.h"
21 #include "base/util.h"
22 #include "subscr.h"
23 #include "drawing.h"
24 using namespace util;
25 extern FFScript FFCore;
26 extern ZModule zcm;
27 extern refInfo *ri;
28 extern script_bitmaps scb;
29 #include <stdio.h>
30 #include <fstream>
31
32 #define DegtoFix(d) ((d)*0.7111111111111)
33 #define RadtoFix(d) ((d)*40.743665431525)
34
35 inline double sd_log2( double n )
36 {
37 // log(n)/log(2) is log2.
38 double v = log( (double)n ) / log( (double)2 );
39 return v;
40 }
41
42 inline bool isPowerOfTwo(int32_t n)
43 {
44 if(n==0)
45 return false;
46
47 return (ceil(sd_log2(n)) == floor(sd_log2(n)));
48 }
49
50
51
52 template<class T> inline
53 fixed degrees_to_fixed(T d)
54 {
55 return ftofix(DegtoFix(d));
56 }
57 template<class T> inline
58 fixed radians_to_fixed(T d)
59 {
60 return ftofix(RadtoFix(d));
61 }
62
63 BITMAP* ScriptDrawingBitmapPool::_parent_bmp = 0;
64
65
66
67 51013 FONT *get_zc_font(int32_t index)
68 {
69 //return getfont(index);
70
5/71
✓ Branch 0 taken 14020 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23183 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1256 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 11860 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✓ Branch 62 taken 694 times.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
51013 switch(index)
71 {
72 default:
73 14020 return zfont;
74
75 case font_z3font:
76 return z3font;
77
78 case font_z3smallfont:
79 23183 return z3smallfont;
80
81 case font_deffont:
82 return deffont;
83
84 case font_lfont:
85 return lfont;
86
87 case font_lfont_l:
88 return lfont_l;
89
90 case font_pfont:
91 return pfont;
92
93 case font_mfont:
94 return mfont;
95
96 case font_ztfont:
97 return ztfont;
98
99 case font_sfont:
100 1256 return sfont;
101
102 case font_sfont2:
103 return sfont2;
104
105 case font_spfont:
106 return spfont;
107
108 case font_ssfont1:
109 return ssfont1;
110
111 case font_ssfont2:
112 return ssfont2;
113
114 case font_ssfont3:
115 return ssfont3;
116
117 case font_ssfont4:
118 return ssfont4;
119
120 case font_gblafont:
121 11860 return gblafont;
122
123 case font_goronfont:
124 return goronfont;
125
126 case font_zoranfont:
127 return zoranfont;
128
129 case font_hylian1font:
130 return hylian1font;
131
132 case font_hylian2font:
133 return hylian2font;
134
135 case font_hylian3font:
136 return hylian3font;
137
138 case font_hylian4font:
139 return hylian4font;
140
141 case font_gboraclefont:
142 return gboraclefont;
143
144 case font_gboraclepfont:
145 return gboraclepfont;
146
147 case font_dsphantomfont:
148 return dsphantomfont;
149
150 case font_dsphantompfont:
151 return dsphantompfont;
152 case font_atari800font: return atari800font;
153 case font_acornfont: return acornfont;
154 case font_adosfont: return adosfont;
155 case font_baseallegrofont: return baseallegrofont;
156 case font_apple2font: return apple2font;
157 case font_apple280colfont: return apple280colfont;
158 case font_apple2gsfont: return apple2gsfont;
159 case font_aquariusfont: return aquariusfont;
160 case font_atari400font: return atari400font;
161 case font_c64font: return c64font;
162 case font_c64hiresfont: return c64hiresfont;
163 case font_cgafont: return cgafont;
164 case font_cocofont: return cocofont;
165 case font_coco2font: return coco2font;
166 case font_coupefon: return coupefont;
167 case font_cpcfon: return cpcfont;
168 case font_fantasyfon: return fantasyfont;
169 case font_fdskanafon: return fdskanafont;
170 case font_fdslikefon: return fdslikefont;
171 case font_fdsromanfon: return fdsromanfont;
172 case font_finalffont: return finalffont;
173 case font_futharkfont: return futharkfont;
174 case font_gaiafont: return gaiafont;
175 case font_hirafont: return hirafont;
176 case font_jpfont: return jpfont;
177 case font_kongfont: return kongfont;
178 case font_manafont: return manafont;
179 case font_mlfont: return mlfont;
180 case font_motfont: return motfont;
181 case font_msxmode0font: return msxmode0font;
182 case font_msxmode1font: return msxmode1font;
183 case font_petfont: return petfont;
184 case font_pstartfont: return pstartfont;
185 case font_saturnfont: return saturnfont;
186 case font_scififont: return scififont;
187 694 case font_sherwoodfont: return sherwoodfont;
188 case font_sinqlfont: return sinqlfont;
189 case font_spectrumfont: return spectrumfont;
190 case font_speclgfont: return speclgfont;
191 case font_ti99font: return ti99font;
192 case font_trsfont: return trsfont;
193 case font_z2font: return z2font;
194 case font_zxfont: return zxfont;
195 case font_lisafont: return lisafont;
196 }
197 51013 }
198
199
200 class TileHelper
201 {
202 public:
203
204 static void OldPutTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
205 {
206 // Past the end of the tile page?
207 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
208 {
209 byte w2=(tile+w)%TILES_PER_ROW;
210 OldPutTile(_Dest, tile, x, y, w-w2, h, color, flip);
211 OldPutTile(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip);
212 return;
213 }
214
215 switch(flip)
216 {
217 case 1:
218 for(int32_t j=0; j<h; j++)
219 for(int32_t k=w-1; k>=0; k--)
220 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip);
221
222 break;
223
224 case 2:
225 for(int32_t j=h-1; j>=0; j--)
226 for(int32_t k=0; k<w; k++)
227 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip);
228
229 break;
230
231 case 3:
232 for(int32_t j=h-1; j>=0; j--)
233 for(int32_t k=w-1; k>=0; k--)
234 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip);
235
236 break;
237
238 case 0:
239 default:
240 for(int32_t j=0; j<h; j++)
241 for(int32_t k=0; k<w; k++)
242 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip);
243
244 break;
245 }
246 }
247
248 13488 static void OverTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
249 {
250 13488 overtileblock16(_Dest,tile,x,y,w,h,color,flip,skiprows);
251 13488 }
252
253 static void OverTileCloaked(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t flip, byte skiprows=0)
254 {
255 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
256 {
257 byte w2=(tile+w)%TILES_PER_ROW;
258 OverTileCloaked(_Dest, tile, x, y, w-w2, h, flip);
259 OverTileCloaked(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, flip);
260 return;
261 }
262
263 switch(flip)
264 {
265 case 1:
266 for(int32_t j=0; j<h; j++)
267 for(int32_t k=w-1; k>=0; k--)
268 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, flip);
269
270 break;
271
272 case 2:
273 for(int32_t j=h-1; j>=0; j--)
274 for(int32_t k=0; k<w; k++)
275 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, flip);
276
277 break;
278
279 case 3:
280 for(int32_t j=h-1; j>=0; j--)
281 for(int32_t k=w-1; k>=0; k--)
282 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, flip);
283
284 break;
285
286 default:
287 for(int32_t j=0; j<h; j++)
288 for(int32_t k=0; k<w; k++)
289 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, flip);
290
291 break;
292 }
293 }
294
295 static void OverTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
296 {
297 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
298 {
299 byte w2=(tile+w)%TILES_PER_ROW;
300 OverTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
301 OverTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
302 return;
303 }
304
305 switch(flip)
306 {
307 case 1:
308 for(int32_t j=0; j<h; j++)
309 for(int32_t k=w-1; k>=0; k--)
310 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
311
312 break;
313
314 case 2:
315 for(int32_t j=h-1; j>=0; j--)
316 for(int32_t k=0; k<w; k++)
317 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
318
319 break;
320
321 case 3:
322 for(int32_t j=h-1; j>=0; j--)
323 for(int32_t k=w-1; k>=0; k--)
324 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
325
326 break;
327
328 default:
329 for(int32_t j=0; j<h; j++)
330 for(int32_t k=0; k<w; k++)
331 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
332
333 break;
334 }
335 }
336
337 static void PutTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
338 {
339 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
340 {
341 byte w2=(tile+w)%TILES_PER_ROW;
342 PutTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
343 PutTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
344 return;
345 }
346
347 switch(flip)
348 {
349 case 1:
350 for(int32_t j=0; j<h; j++)
351 for(int32_t k=w-1; k>=0; k--)
352 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
353
354 break;
355
356 case 2:
357 for(int32_t j=h-1; j>=0; j--)
358 for(int32_t k=0; k<w; k++)
359 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
360
361 break;
362
363 case 3:
364 for(int32_t j=h-1; j>=0; j--)
365 for(int32_t k=w-1; k>=0; k--)
366 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
367
368 break;
369
370 default:
371 for(int32_t j=0; j<h; j++)
372 for(int32_t k=0; k<w; k++)
373 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
374
375 break;
376 }
377 }
378 };
379
380
381
382
383 34260 void do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
384 {
385 //sdci[1]=layer
386 //sdci[2]=x
387 //sdci[3]=y
388 //sdci[4]=x2
389 //sdci[5]=y2
390 //sdci[6]=color
391 //sdci[7]=scale factor
392 //sdci[8]=rotation anchor x
393 //sdci[9]=rotation anchor y
394 //sdci[10]=rotation angle
395 //sdci[11]=fill
396 //sdci[12]=opacity
397
1/2
✓ Branch 0 taken 34260 times.
✗ Branch 1 not taken.
34260 if(sdci[7]==0) //scale
398 {
399 return;
400 }
401
402 34260 int32_t x1=sdci[2]/10000;
403 34260 int32_t y1=sdci[3]/10000;
404 34260 int32_t x2=sdci[4]/10000;
405 34260 int32_t y2=sdci[5]/10000;
406
407
1/2
✓ Branch 0 taken 34260 times.
✗ Branch 1 not taken.
34260 if(x1>x2)
408 {
409 zc_swap(x1,x2);
410 }
411
412
1/2
✓ Branch 0 taken 34260 times.
✗ Branch 1 not taken.
34260 if(y1>y2)
413 {
414 zc_swap(y1,y2);
415 }
416
417
1/2
✓ Branch 0 taken 34260 times.
✗ Branch 1 not taken.
34260 if(sdci[7] != 10000)
418 {
419 int32_t w=x2-x1+1;
420 int32_t h=y2-y1+1;
421 int32_t w2=(w*sdci[7])/10000;
422 int32_t h2=(h*sdci[7])/10000;
423 x1=x1-((w2-w)/2);
424 x2=x2+((w2-w)/2);
425 y1=y1-((h2-h)/2);
426 y2=y2+((h2-h)/2);
427 }
428
429 34260 int32_t color=sdci[6]/10000;
430
431
1/2
✓ Branch 0 taken 34260 times.
✗ Branch 1 not taken.
34260 if(sdci[12]/10000<=127) //translucent
432 {
433 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
434 }
435
436
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34260 times.
34260 if(sdci[10]==0) //no rotation
437 {
438
2/2
✓ Branch 0 taken 1366 times.
✓ Branch 1 taken 32894 times.
34260 if(sdci[11]) //filled
439 {
440 32894 rectfill(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
441 32894 }
442 else //outline
443 {
444 1366 rect(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
445 }
446 34260 }
447 else //rotate
448 {
449 int32_t xy[16];
450 int32_t rx=sdci[8]/10000;
451 int32_t ry=sdci[9]/10000;
452 fixed ra1=itofix(sdci[10]%10000)/10000;
453 fixed ra2=itofix(sdci[10]/10000);
454 fixed ra=ra1+ra2;
455 ra = (ra/360)*256;
456
457 fixed fcosa = fixcos(ra);
458 fixed fsina = fixsin(ra);
459
460 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
461 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
462 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
463 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
464 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
465 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
466 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
467 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
468 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
469 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
470 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
471 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
472 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
473 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
474 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
475 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
476
477 if(sdci[11]) //filled
478 {
479 polygon(bmp, 4, xy, color);
480 }
481 else //outline
482 {
483 line(bmp, xy[0], xy[1], xy[10], xy[11], color);
484 line(bmp, xy[2], xy[3], xy[12], xy[13], color);
485 line(bmp, xy[4], xy[5], xy[14], xy[15], color);
486 line(bmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
487 }
488 }
489
490 34260 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
491 34260 }
492
493 void do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
494 {
495 //sdci[1]=layer
496 //sdci[2]=x
497 //sdci[3]=y
498 //sdci[4]=tile
499 //sdci[5]=cset
500 //sdci[6]=width
501 //sdci[7]=height
502 //sdci[8]=overlay
503 //sdci[9]=opacity
504
505 int32_t x=sdci[2]/10000;
506 int32_t y=sdci[3]/10000;
507
508 int32_t tile=sdci[4]/10000;
509 int32_t cs=sdci[5]/10000;
510 int32_t w=sdci[6]/10000;
511 int32_t h=sdci[7]/10000;
512 bool overlay=sdci[8];
513 bool trans=(sdci[9]/10000<=127);
514
515 frame2x2(bmp, &QMisc, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
516 }
517
518
519
520 void do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
521 {
522 //sdci[1]=layer
523 //sdci[2]=x
524 //sdci[3]=y
525 //sdci[4]=radius
526 //sdci[5]=color
527 //sdci[6]=scale factor
528 //sdci[7]=rotation anchor x
529 //sdci[8]=rotation anchor y
530 //sdci[9]=rotation angle
531 //sdci[10]=fill
532 //sdci[11]=opacity
533 if(sdci[6]==0) //scale
534 {
535 return;
536 }
537
538 int32_t x1=sdci[2]/10000;
539 int32_t y1=sdci[3]/10000;
540 qword r=sdci[4];
541
542 if(sdci[6] != 10000)
543 {
544 r*=sdci[6];
545 r/=10000;
546 }
547
548 r/=10000;
549 int32_t color=sdci[5]/10000;
550
551 if(sdci[11]/10000<=127) //translucent
552 {
553 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
554 }
555
556 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
557 {
558 int32_t xy[2];
559 int32_t rx=sdci[7]/10000;
560 int32_t ry=sdci[8]/10000;
561 fixed ra1=itofix(sdci[9]%10000)/10000;
562 fixed ra2=itofix(sdci[9]/10000);
563 fixed ra=ra1+ra2;
564 ra = (ra/360)*256;
565
566 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
567 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
568 x1=xy[0];
569 y1=xy[1];
570 }
571
572 if(sdci[10]) //filled
573 {
574 circlefill(bmp, x1+xoffset, y1+yoffset, r, color);
575 }
576 else //outline
577 {
578 circle(bmp, x1+xoffset, y1+yoffset, r, color);
579 }
580
581 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
582 }
583
584
585 void do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
586 {
587 //sdci[1]=layer
588 //sdci[2]=x
589 //sdci[3]=y
590 //sdci[4]=radius
591 //sdci[5]=start angle
592 //sdci[6]=end angle
593 //sdci[7]=color
594 //sdci[8]=scale factor
595 //sdci[9]=rotation anchor x
596 //sdci[10]=rotation anchor y
597 //sdci[11]=rotation angle
598 //sdci[12]=closed
599 //sdci[13]=fill
600 //sdci[14]=opacity
601
602 if(sdci[8]==0) //scale
603 {
604 return;
605 }
606
607 int32_t cx=sdci[2]/10000;
608 int32_t cy=sdci[3]/10000;
609 qword r=sdci[4];
610
611 if(sdci[8] != 10000)
612 {
613 r*=sdci[8];
614 r/=10000;
615 }
616
617 r/=10000;
618
619 int32_t color=sdci[7]/10000;
620
621 fixed ra1=itofix(sdci[11]%10000)/10000;
622 fixed ra2=itofix(sdci[11]/10000);
623 fixed ra=ra1+ra2;
624 ra = (ra/360)*256;
625
626
627 fixed a1=itofix(sdci[5]%10000)/10000;
628 fixed a2=itofix(sdci[5]/10000);
629 fixed sa=a1+a2;
630 sa = (sa/360)*256;
631
632 a1=itofix(sdci[6]%10000)/10000;
633 a2=itofix(sdci[6]/10000);
634 fixed ea=a1+a2;
635 ea = (ea/360)*256;
636
637 if(sdci[11]!=0) //rotation
638 {
639 int32_t rx=sdci[9]/10000;
640 int32_t ry=sdci[10]/10000;
641
642 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
643 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
644 ea-=ra;
645 sa-=ra;
646 }
647
648 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
649 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
650
651 if(sdci[12]) //closed
652 {
653 if(sdci[13]) //filled
654 {
655 clear_bitmap(prim_bmp);
656 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
657 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
658 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
659 int fillx = zc_max(0,fx)+xoffset;
660 int filly = zc_max(0,fy)+yoffset;
661 zprint2("Screen->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
662 floodfill(prim_bmp, fillx, filly, color);
663
664 if(sdci[14]/10000<=127) //translucent
665 {
666 draw_trans_sprite(bmp, prim_bmp, 0,0);
667 }
668 else
669 {
670 draw_sprite(bmp, prim_bmp, 0,0);
671 }
672 }
673 else
674 {
675 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
676 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
677 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
678 }
679 }
680 else
681 {
682 if(sdci[14]/10000<=127) //translucent
683 {
684 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
685 }
686
687 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
688 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
689 }
690 }
691
692
693 void do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
694 {
695 //sdci[1]=layer
696 //sdci[2]=x
697 //sdci[3]=y
698 //sdci[4]=radiusx
699 //sdci[5]=radiusy
700 //sdci[6]=color
701 //sdci[7]=scale factor
702 //sdci[8]=rotation anchor x
703 //sdci[9]=rotation anchor y
704 //sdci[10]=rotation angle
705 //sdci[11]=fill
706 //sdci[12]=opacity
707
708 if(sdci[7]==0) //scale
709 {
710 return;
711 }
712
713 int32_t x1=sdci[2]/10000;
714 int32_t y1=sdci[3]/10000;
715 int32_t radx=sdci[4]/10000;
716 radx*=sdci[7]/10000;
717 int32_t rady=sdci[5]/10000;
718 rady*=sdci[7]/10000;
719 int32_t color=sdci[6]/10000;
720 float rotation = sdci[10]/10000;
721
722 int32_t rx=sdci[8]/10000;
723 int32_t ry=sdci[9]/10000;
724 fixed ra1=itofix(sdci[10]%10000)/10000;
725 fixed ra2=itofix(sdci[10]/10000);
726 fixed ra=ra1+ra2;
727 ra = (ra/360)*256;
728
729 int32_t xy[2];
730 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
731 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
732 x1=xy[0];
733 y1=xy[1];
734
735 if(radx<1||rady<1||radx>255||rady>255) return;
736
737 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
738
739 if(sdci[11]) //filled
740 {
741
742 if(sdci[12]/10000<128) //translucent
743 {
744 clear_bitmap(prim_bmp);
745 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
746 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
747 draw_trans_sprite(bmp, prim_bmp, 0, 0);
748 }
749 else // no opacity
750 {
751 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
752 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
753 }
754 }
755 else //not filled
756 {
757 if(sdci[12]/10000<128) //translucent
758 {
759 clear_bitmap(prim_bmp);
760 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
761 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
762 draw_trans_sprite(bmp, prim_bmp, 0, 0);
763 }
764 else // no opacity
765 {
766 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
767 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
768 }
769 }
770
771 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
772 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
773 // the ellipse, but it shouldn't be used anyway.
774 if(color==0)
775 {
776 // This is very slow, so check the smallest possible square
777 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
778 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
779
780 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
781 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
782 if(getpixel(bmp, x, y)==255)
783 putpixel(bmp, x, y, 0);
784 }
785
786 script_drawing_commands.ReleaseSubBitmap(bitty);
787 }
788
789
790 void do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
791 {
792 //sdci[1]=layer
793 //sdci[2]=x
794 //sdci[3]=y
795 //sdci[4]=x2
796 //sdci[5]=y2
797 //sdci[6]=color
798 //sdci[7]=scale factor
799 //sdci[8]=rotation anchor x
800 //sdci[9]=rotation anchor y
801 //sdci[10]=rotation angle
802 //sdci[11]=opacity
803 if(sdci[7]==0) //scale
804 {
805 return;
806 }
807
808 int32_t x1=sdci[2]/10000;
809 int32_t y1=sdci[3]/10000;
810 int32_t x2=sdci[4]/10000;
811 int32_t y2=sdci[5]/10000;
812
813 if(sdci[7] != 10000)
814 {
815 int32_t w=x2-x1+1;
816 int32_t h=y2-y1+1;
817 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
818 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
819 x1=x1-((w2-w)/2);
820 x2=x2+((w2-w)/2);
821 y1=y1-((h2-h)/2);
822 y2=y2+((h2-h)/2);
823 }
824
825 int32_t color=sdci[6]/10000;
826
827 if(sdci[11]/10000<=127) //translucent
828 {
829 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
830 }
831
832 if(sdci[10]!=0) //rotation
833 {
834 int32_t xy[4];
835 int32_t rx=sdci[8]/10000;
836 int32_t ry=sdci[9]/10000;
837 fixed ra1=itofix(sdci[10]%10000)/10000;
838 fixed ra2=itofix(sdci[10]/10000);
839 fixed ra=ra1+ra2;
840
841 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
842 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
843 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
844 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
845 x1=xy[0];
846 y1=xy[1];
847 x2=xy[2];
848 y2=xy[3];
849 }
850
851 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
852 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
853 }
854
855 void do_linesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
856 {
857 //sdci[1]=layer
858 //sdci[2]=array[10] = { x, y, x2, y2, colour, scale, rx, ry, angle, opacity }
859
860 //sdci[2]=x
861 //sdci[3]=y
862 //sdci[4]=x2
863 //sdci[5]=y2
864 //sdci[6]=color
865 //sdci[7]=scale factor
866 //sdci[8]=rotation anchor x
867 //sdci[9]=rotation anchor y
868 //sdci[10]=rotation angle
869 //sdci[11]=opacity
870 //if(sdci[7]==0) //scale
871 //{
872 // return;
873 //}
874
875 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
876
877 if(!v_ptr)
878 {
879 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
880 return;
881 }
882
883 std::vector<int32_t> &v = *v_ptr;
884
885 if(v.empty())
886 return;
887 //Z_scripterrlog("PutPixels reached line %d\n", 983);
888
889 int32_t* pos = &v[0];
890 int32_t sz = v.size();
891
892 for ( int32_t q = 0; q < sz; q+=10 )
893 {
894
895 int32_t x1 = v.at(q);
896 Z_scripterrlog("Lines( x1 ) is: %d\n", x1);
897 int32_t y1 = v.at(q+1);
898 Z_scripterrlog("Lines( x2 ) is: %d\n", y1);
899 int32_t x2 = v.at(q+2);
900 Z_scripterrlog("Lines( x2 ) is: %d\n", x2);
901 int32_t y2 = v.at(q+3);
902 Z_scripterrlog("Lines( y2 ) is: %d\n", y2);
903 int32_t color = v.at(q+4);
904 Z_scripterrlog("Lines( colour ) is: %d\n", color);
905 Z_scripterrlog("Lines( scale ) is: %d\n", v.at(q+5));
906 if (v.at(q+5) == 0) { Z_scripterrlog("Lines() aborting due to scale\n"); return; }//scale
907
908 if( v.at(q+5) != 10000)
909 {
910 int32_t w=x2-x1+1;
911 int32_t h=y2-y1+1;
912 int32_t w2=int32_t(w*((double)v.at(q+5)));
913 int32_t h2=int32_t(h*((double)v.at(q+5)));
914 x1=x1-((w2-w)/2);
915 x2=x2+((w2-w)/2);
916 y1=y1-((h2-h)/2);
917 y2=y2+((h2-h)/2);
918 }
919
920
921 Z_scripterrlog("Lines( opacity ) is: %d\n", v.at(q+9));
922 if(v.at(q+9) <= 127) //translucent
923 {
924 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
925 }
926 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
927 Z_scripterrlog("Lines( rotation ) is: %d\n", v.at(q+8));
928 Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+6));
929 Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+7));
930 if( v.at(q+8) !=0 ) //rotation
931 {
932 int32_t xy[4];
933
934 int32_t rx = v.at(q+6);
935
936 int32_t ry = v.at(q+7);
937
938 fixed ra1=itofix(v.at(q+8) % 1);
939 fixed ra2=itofix(v.at(q+8));
940 fixed ra=ra1+ra2;
941
942 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
943 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
944 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
945 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
946 x1=xy[0];
947 y1=xy[1];
948 x2=xy[2];
949 y2=xy[3];
950 }
951 Z_scripterrlog("Lines( xofs ) is: %d\n", xoffset);
952 Z_scripterrlog("Lines( yofs ) is: %d\n", yoffset);
953 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
954 }
955 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
956 }
957
958 void do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
959 {
960 //sdci[1]=layer
961 //sdci[2]=point count
962 //sdci[3]array[]
963 //sdci[4] = colour
964 //sdci[5] = opacity
965
966 int32_t col = sdci[4]/10000;
967 int32_t op = sdci[5]/10000;
968
969 //bool brokenOffset= ( (get_bit(extra_rules, er_BITMAPOFFSET)!=0) || (get_bit(quest_rules,qr_BITMAPOFFSETFIX)!=0) );
970 //Z_scripterrlog("Broken offset rule for Polygon() is: %s\n", brokenOffset ? "ON" : "OFF");
971 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
972
973 if(!v_ptr)
974 {
975 al_trace("Screen->Polygon: Vector pointer is null! Internal error. \n");
976 return;
977 }
978
979 std::vector<int32_t> &v = *v_ptr;
980
981 if(v.empty())
982 return;
983 //Z_scripterrlog("PutPixels reached line %d\n", 983);
984
985 int32_t* pos = &v[0];
986 int32_t sz = v.size();
987 int32_t numpoints = (sdci[2]/10000);
988 if(sz & 1) --sz; //even amount only
989 if(numpoints > sz/2) //cap to array
990 numpoints = sz/2;
991 if(numpoints < 1)
992 return; //Don't draw 0 or negative point count
993
994 //Fix the draw Y offset. -Z 20th June, 2019
995 for ( int32_t q = 1; q < sz; q+=2 )
996 {
997 pos[q] += yoffset;
998 }
999 if(op <= 127) //translucent
1000 {
1001 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1002 }
1003 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1004
1005 polygon(bmp, numpoints, (int32_t*)pos, col);
1006 //polygon(bmp, (sdci[2]/10000), &v, col);
1007 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1008 }
1009
1010 void bmp_do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1011 {
1012 //sdci[1]=layer
1013 //sdci[2]=point count
1014 //sdci[3]array[]
1015 //sdci[4] = colour
1016 //sdci[5] = opacity
1017
1018 int32_t col = sdci[4]/10000;
1019 int32_t op = sdci[5]/10000;
1020
1021 if ( sdci[17] <= 0 )
1022 {
1023 Z_scripterrlog("bitmap->Rectangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
1024 return;
1025 }
1026 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
1027 if ( refbmp == NULL ) return;
1028
1029 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
1030
1031 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1032
1033 if(!v_ptr)
1034 {
1035 al_trace("Screen->Polygon: Vector pointer is null! Internal error. \n");
1036 return;
1037 }
1038
1039 std::vector<int32_t> &v = *v_ptr;
1040
1041 if(v.empty())
1042 return;
1043 //Z_scripterrlog("PutPixels reached line %d\n", 983);
1044
1045 int32_t* pos = &v[0];
1046 int32_t sz = v.size();
1047 int32_t numpoints = (sdci[2]/10000);
1048 if(sz & 1) --sz; //even amount only
1049 if(numpoints > sz/2) //cap to array
1050 numpoints = sz/2;
1051 if(numpoints < 1)
1052 return; //Don't draw 0 or negative point count
1053
1054 //Fix the draw Y offset. -Z 20th June, 2019
1055 for ( int32_t q = 1; q < sz; q+=2 )
1056 {
1057 pos[q] += yoffset;
1058 }
1059 if(op <= 127) //translucent
1060 {
1061 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1062 }
1063 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1064
1065 polygon(refbmp, numpoints, (int32_t*)pos, col);
1066 //polygon(refbmp, (sdci[2]/10000), &v, col);
1067 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1068 }
1069
1070 void do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1071 {
1072 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
1073
1074 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
1075 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
1076 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
1077 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
1078 };
1079
1080 if(sdci[11]/10000 < 128) //translucent
1081 {
1082 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1083 }
1084
1085 spline(bmp, points, sdci[10]/10000);
1086
1087 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1088 }
1089
1090
1091 void do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1092 {
1093 //sdci[1]=layer
1094 //sdci[2]=x
1095 //sdci[3]=y
1096 //sdci[4]=color
1097 //sdci[5]=rotation anchor x
1098 //sdci[6]=rotation anchor y
1099 //sdci[7]=rotation angle
1100 //sdci[8]=opacity
1101 int32_t x1=sdci[2]/10000;
1102 int32_t y1=sdci[3]/10000;
1103 int32_t color=sdci[4]/10000;
1104
1105 if(sdci[8]/10000<=127) //translucent
1106 {
1107 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1108 }
1109
1110 if(sdci[7]!=0) //rotation
1111 {
1112 int32_t xy[2];
1113 int32_t rx=sdci[5]/10000;
1114 int32_t ry=sdci[6]/10000;
1115 fixed ra1=itofix(sdci[7]%10000)/10000;
1116 fixed ra2=itofix(sdci[7]/10000);
1117 fixed ra=ra1+ra2;
1118
1119 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1120 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1121 x1=xy[0];
1122 y1=xy[1];
1123 }
1124
1125 putpixel(bmp, x1+xoffset, y1+yoffset, color);
1126 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1127 }
1128
1129 void do_putpixelsr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1130 {
1131 //Z_scripterrlog("Starting putpixels()%s\n");
1132 //sdci[1]=layer
1133 //sdci[2]=array {x,y,colour,opacity}
1134 //sdci[3]=rotation anchor x
1135 //sdci[4]=rotation anchor y
1136 //sdci[5]=rotation angle
1137
1138
1139 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1140
1141 if(!v_ptr)
1142 {
1143 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1144 return;
1145 }
1146
1147 std::vector<int32_t> &v = *v_ptr;
1148
1149 if(v.empty())
1150 return;
1151 //Z_scripterrlog("PutPixels reached line %d\n", 983);
1152
1153 int32_t* pos = &v[0];
1154 int32_t sz = v.size();
1155 //Z_scripterrlog("Vector size is: %d\n", sz);
1156 //for ( int32_t m = 0; m < 256; ++m ) Z_scripterrlog("Vector contents at pos[%d]: %d\n", m, pos[m]);
1157
1158 //FFCore.getValues(sdci[2]/10000, points, sz);
1159
1160
1161 int32_t x1 = 0;
1162 int32_t y1 = 0;
1163
1164 for ( int32_t q = 0; q < sz; q+=4 )
1165 {
1166 //Z_scripterrlog("Vector q: %d\n", q);
1167 //if ( q > sz-1 ) break;
1168 x1 = v.at(q); //pos[q];
1169 y1 = v.at(q+1); //pos[q+1];
1170 //Z_scripterrlog("x1 is: %d\n", x1);
1171 //Z_scripterrlog("y1 is: %d\n", 1);
1172 if(sdci[5]!=0) //rotation
1173 {
1174 int32_t xy[2];
1175 int32_t rx=sdci[3]/10000;
1176 int32_t ry=sdci[4]/10000;
1177 fixed ra1=itofix(sdci[5]%10000)/10000;
1178 fixed ra2=itofix(sdci[5]/10000);
1179 fixed ra=ra1+ra2;
1180
1181 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1182 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1183 x1=xy[0];
1184 y1=xy[1];
1185 }
1186 //Z_scripterrlog("PutPixels()%s value is %d\n","x",x1);
1187 //Z_scripterrlog("PutPixels()%s value is %d\n","y",y1);
1188 //Z_scripterrlog("PutPixels()%s value is %d\n","colour",points[q+2]);
1189 if ( v.at(q+3) /*pos[q+3]*/ < 128 ) drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1190 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1191 putpixel(bmp, x1+xoffset, y1+yoffset, v.at(q+2) /*pos[q+2]*/);
1192 //if ( points[q+3] < 128 )
1193
1194 //else drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1195 }
1196 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1197 }
1198
1199 4893 void do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1200 {
1201 //sdci[1]=layer
1202 //sdci[2]=x
1203 //sdci[3]=y
1204 //sdci[4]=tile
1205 //sdci[5]=tile width
1206 //sdci[6]=tile height
1207 //sdci[7]=color (cset)
1208 //sdci[8]=scale x
1209 //sdci[9]=scale y
1210 //sdci[10]=rotation anchor x
1211 //sdci[11]=rotation anchor y
1212 //sdci[12]=rotation angle
1213 //sdci[13]=flip
1214 //sdci[14]=transparency
1215 //sdci[15]=opacity
1216
1217 4893 int32_t w = sdci[5]/10000;
1218 4893 int32_t h = sdci[6]/10000;
1219
1220
4/8
✓ Branch 0 taken 4893 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4893 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4893 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4893 times.
4893 if(w < 1 || h < 1 || h > 20 || w > 20)
1221 {
1222 return;
1223 }
1224
1225 4893 int32_t xscale=sdci[8]/10000;
1226 4893 int32_t yscale=sdci[9]/10000;
1227 4893 int32_t rx = sdci[10]/10000;
1228 4893 int32_t ry = sdci[11]/10000;
1229 4893 float rotation=sdci[12]/10000;
1230 4893 int32_t flip=(sdci[13]/10000)&3;
1231 4893 bool transparency=sdci[14]!=0;
1232 4893 int32_t opacity=sdci[15]/10000;
1233 4893 int32_t color=sdci[7]/10000;
1234
1235 4893 int32_t x1=sdci[2]/10000;
1236 4893 int32_t y1=sdci[3]/10000;
1237
1238 //don't scale if it's not safe to do so
1239 4893 bool canscale = true;
1240
1241
2/4
✓ Branch 0 taken 4893 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4893 times.
4893 if(xscale==0||yscale==0)
1242 {
1243 return;
1244 }
1245
1246
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4893 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4893 if(xscale<=0||yscale<=0)
1247 4893 canscale = false; //default size
1248
1249
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4893 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4893 times.
4893 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1250 {
1251 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
1252
1253 if(transparency) //transparency
1254 {
1255 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1256 }
1257 else //no transparency
1258 {
1259 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1260 }
1261
1262 if(rotation != 0)
1263 {
1264 //low negative values indicate no anchor-point rotation
1265 if(rx>-777||ry>-777)
1266 {
1267 int32_t xy[2];
1268 fixed ra1=itofix(sdci[12]%10000)/10000;
1269 fixed ra2=itofix(sdci[12]/10000);
1270 fixed ra=ra1+ra2;
1271 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1272 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1273 x1=xy[0];
1274 y1=xy[1];
1275 }
1276
1277 if(canscale) //scale first
1278 {
1279 //damnit all, .. fixme.
1280 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1281 clear_bitmap(tempbit);
1282
1283 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1284
1285 if(opacity < 128)
1286 {
1287 clear_bitmap(prim_bmp);
1288 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1289 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1290 }
1291 else
1292 {
1293 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1294 }
1295
1296 destroy_bitmap(tempbit);
1297 }
1298 else //no scale
1299 {
1300 if(opacity < 128)
1301 {
1302 clear_bitmap(prim_bmp);
1303 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1304 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1305 }
1306 else
1307 {
1308 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1309 }
1310 }
1311 }
1312 else //scale only
1313 {
1314 if(canscale)
1315 {
1316 if(opacity<128)
1317 {
1318 clear_bitmap(prim_bmp);
1319 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1320 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1321 }
1322 else
1323 {
1324 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1325 }
1326 }
1327 else //error -do not scale
1328 {
1329 if(opacity<128)
1330 {
1331 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1332 }
1333 else
1334 {
1335 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1336 }
1337 }
1338 }
1339
1340 script_drawing_commands.ReleaseSubBitmap(pbitty);
1341
1342 }
1343 else // no scale or rotation
1344 {
1345
1/2
✓ Branch 0 taken 4893 times.
✗ Branch 1 not taken.
4893 if(transparency)
1346 {
1347
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4893 times.
4893 if(opacity<=127)
1348 TileHelper::OverTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1349 else
1350 4893 TileHelper::OverTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1351 4893 }
1352 else
1353 {
1354 if(opacity<=127)
1355 TileHelper::PutTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1356 else
1357 TileHelper::OldPutTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1358 }
1359 }
1360 4893 }
1361
1362 void do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1363 {
1364 //sdci[1]=layer
1365 //sdci[2]=x
1366 //sdci[3]=y
1367 //sdci[4]=tile
1368 //sdci[5]=tile width
1369 //sdci[6]=tile height
1370 //sdci[7]=flip
1371
1372 int32_t w = sdci[5]/10000;
1373 int32_t h = sdci[6]/10000;
1374
1375 if(w < 1 || h < 1 || h > 20 || w > 20)
1376 {
1377 return;
1378 }
1379
1380 int32_t flip=(sdci[7]/10000)&3;
1381
1382 int32_t x1=sdci[2]/10000;
1383 int32_t y1=sdci[3]/10000;
1384
1385 TileHelper::OverTileCloaked(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
1386 }
1387
1388
1389 8328 void do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1390 {
1391 //sdci[1]=layer
1392 //sdci[2]=x
1393 //sdci[3]=y
1394 //sdci[4]=combo
1395 //sdci[5]=tile width
1396 //sdci[6]=tile height
1397 //sdci[7]=color (cset)
1398 //sdci[8]=scale x
1399 //sdci[9]=scale y
1400 //sdci[10]=rotation anchor x
1401 //sdci[11]=rotation anchor y
1402 //sdci[12]=rotation angle
1403 //sdci[13]=frame
1404 //sdci[14]=flip
1405 //sdci[15]=transparency
1406 //sdci[16]=opacity
1407
1408 8328 int32_t w = sdci[5]/10000;
1409 8328 int32_t h = sdci[6]/10000;
1410
1411
4/8
✓ Branch 0 taken 8328 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8328 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8328 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 8328 times.
8328 if(w<1||h<1||h>20||w>20)
1412 {
1413 return;
1414 }
1415 8328 int32_t cmb = (sdci[4]/10000);
1416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8328 times.
8328 if((unsigned)cmb >= MAXCOMBOS)
1417 {
1418 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1419 return;
1420 }
1421
1422 8328 int32_t xscale=sdci[8]/10000;
1423 8328 int32_t yscale=sdci[9]/10000;
1424 8328 int32_t rx = sdci[10]/10000; //these work now
1425 8328 int32_t ry = sdci[11]/10000; //these work now
1426 8328 float rotation=sdci[12]/10000;
1427
1428 8328 bool transparency=sdci[15]!=0;
1429 8328 int32_t opacity=sdci[16]/10000;
1430 8328 int32_t color=sdci[7]/10000;
1431 8328 int32_t x1=sdci[2]/10000;
1432 8328 int32_t y1=sdci[3]/10000;
1433
1434 8328 const newcombo & c = combobuf[cmb];
1435 8328 int32_t tiletodraw = combo_tile(c, x1, y1);
1436 8328 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
1437 8328 int32_t skiprows=c.skipanimy;
1438
1439
1440 //don't scale if it's not safe to do so
1441 8328 bool canscale = true;
1442
1443
2/4
✓ Branch 0 taken 8328 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8328 times.
8328 if(xscale==0||yscale==0)
1444 {
1445 return;
1446 }
1447
1448
2/4
✓ Branch 0 taken 8328 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8328 times.
8328 if(xscale<=0||yscale<=0)
1449 canscale = false; //default size
1450
1451
1/4
✓ Branch 0 taken 8328 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8328 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1452 {
1453 8328 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
1454
1455
1/2
✓ Branch 0 taken 8328 times.
✗ Branch 1 not taken.
8328 if(transparency)
1456 {
1457 8328 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1458 8328 }
1459 else //no transparency
1460 {
1461 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1462 }
1463
1464
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8328 times.
8328 if(rotation != 0) // rotate
1465 {
1466 //fixed point sucks ;0
1467 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
1468 {
1469 int32_t xy[2];
1470 fixed ra1=itofix(sdci[12]%10000)/10000;
1471 fixed ra2=itofix(sdci[12]/10000);
1472 fixed ra=ra1+ra2;
1473 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1474 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1475 x1=xy[0];
1476 y1=xy[1];
1477 }
1478
1479 if(canscale) //scale first
1480 {
1481 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1482 clear_bitmap(tempbit);
1483
1484 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1485
1486 if(opacity < 128)
1487 {
1488 clear_bitmap(prim_bmp);
1489 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1490 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1491 }
1492 else
1493 {
1494 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1495 }
1496
1497 destroy_bitmap(tempbit);
1498 }
1499 else //no scale
1500 {
1501 if(opacity < 128)
1502 {
1503 clear_bitmap(prim_bmp);
1504 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1505 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1506 }
1507 else
1508 {
1509 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1510 }
1511 }
1512 }
1513 else //scale only
1514 {
1515
1/2
✓ Branch 0 taken 8328 times.
✗ Branch 1 not taken.
8328 if(canscale)
1516 {
1517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8328 times.
8328 if(opacity<128)
1518 {
1519 clear_bitmap(prim_bmp);
1520 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1521 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1522 }
1523 else
1524 {
1525 8328 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1526 }
1527 8328 }
1528 else //error -do not scale
1529 {
1530 if(opacity<128)
1531 {
1532 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1533 }
1534 else
1535 {
1536 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1537 }
1538 }
1539 }
1540
1541 8328 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
1542 8328 }
1543 else // no scale or rotation
1544 {
1545 if(transparency)
1546 {
1547 if(opacity<=127)
1548 TileHelper::OverTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1549 else
1550 TileHelper::OverTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1551 }
1552 else
1553 {
1554 if(opacity<=127)
1555 TileHelper::PutTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1556 else
1557 TileHelper::OldPutTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1558 }
1559 }
1560 8328 }
1561
1562 void do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1563 {
1564 //sdci[1]=layer
1565 //sdci[2]=x
1566 //sdci[3]=y
1567 //sdci[4]=combo
1568 //sdci[5]=tile width
1569 //sdci[6]=tile height
1570 //sdci[7]=flip
1571
1572 int32_t w = sdci[5]/10000;
1573 int32_t h = sdci[6]/10000;
1574
1575 if(w<1||h<1||h>20||w>20)
1576 {
1577 return;
1578 }
1579 int32_t cmb = (sdci[4]/10000);
1580 if((unsigned)cmb >= MAXCOMBOS)
1581 {
1582 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1583 return;
1584 }
1585
1586 int32_t x1=sdci[2]/10000;
1587 int32_t y1=sdci[3]/10000;
1588
1589 const newcombo & c = combobuf[cmb];
1590 int32_t tiletodraw = combo_tile(c, x1, y1);
1591 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
1592 int32_t skiprows=c.skipanimy;
1593
1594 TileHelper::OverTileCloaked(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
1595 }
1596
1597
1598 34286 void do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1599 {
1600 /* layer, x, y, tile, color opacity */
1601
1602 34286 int32_t opacity = sdci[6]/10000;
1603
1604
2/2
✓ Branch 0 taken 6688 times.
✓ Branch 1 taken 27598 times.
34286 if(opacity < 128)
1605 6688 overtiletranslucent16(bmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0, opacity);
1606 else
1607 27598 overtile16(bmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0);
1608 34286 }
1609
1610 void do_fasttilesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1611 {
1612 /* layer, x, y, tile, color opacity */
1613
1614 //sdci[1]=layer
1615 //sdci[2]=array {x,y,tile,colour,opacity}
1616
1617 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1618
1619 if(!v_ptr)
1620 {
1621 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1622 return;
1623 }
1624
1625 std::vector<int32_t> &v = *v_ptr;
1626
1627 if(v.empty())
1628 return;
1629 //Z_scripterrlog("PutPixels reached line %d\n", 983);
1630
1631 int32_t* pos = &v[0];
1632 int32_t sz = v.size();
1633
1634 for ( int32_t q = 0; q < sz; q+=5 )
1635 {
1636
1637 if(v.at(q+4) < 128)
1638 overtiletranslucent16(bmp, v.at(q), xoffset+(v.at(q+1)), yoffset+(v.at(q+2)), v.at(q+3), 0, v.at(q+4));
1639 else
1640 overtile16(bmp, v.at(q), xoffset+(v.at(q+1)), yoffset+(v.at(q+2)), v.at(q+3), 0);
1641 }
1642 }
1643
1644
1645
1646 4233 void do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1647 {
1648 /* layer, x, y, tile, color opacity */
1649
1650 4233 int32_t opacity = sdci[6] / 10000;
1651 4233 int32_t x1 = sdci[2] / 10000;
1652 4233 int32_t y1 = sdci[3] / 10000;
1653
1654 4233 int32_t cmb = (sdci[4]/10000);
1655
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4233 times.
4233 if((unsigned)cmb >= MAXCOMBOS)
1656 {
1657 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1658 return;
1659 }
1660 //if( index >= MAXCOMBOS ) return; //bleh.
1661 /*
1662 const newcombo & c = combobuf[index];
1663
1664 if(opacity < 128)
1665 overtiletranslucent16(bmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip, opacity);
1666 else
1667 overtile16(bmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip);
1668 */
1669
1670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4233 times.
4233 if(opacity < 128)
1671 {
1672 //void overcomboblocktranslucent(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h, int32_t opacity)
1673 overcomboblocktranslucent(bmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1, 128);
1674
1675 }
1676 else
1677 {
1678 //overcomboblock(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h)
1679 4233 overcomboblock(bmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1);
1680 }
1681 4233 }
1682
1683 void do_fastcombosr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1684 {
1685 /* layer, x, y, combo, cset, opacity */
1686
1687 //sdci[1]=layer
1688 //sdci[2]=array {x,y,combo,cset,opacity}
1689
1690 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1691
1692 if(!v_ptr)
1693 {
1694 al_trace("Screen->FastCombos: Vector pointer is null! Internal error. \n");
1695 return;
1696 }
1697
1698 std::vector<int32_t> &v = *v_ptr;
1699
1700 if(v.empty())
1701 return;
1702
1703 int32_t* pos = &v[0];
1704 int32_t sz = v.size();
1705
1706 for ( int32_t q = 0; q < sz; q+=5 )
1707 {
1708 if((unsigned)(v.at(q+2)) >= MAXCOMBOS)
1709 {
1710 Z_scripterrlog("FastCombos() cannot draw combo '%d', as it is out of bounds.\n", v.at(q+2));
1711 continue;
1712 }
1713 if(v.at(q+4) < 128)
1714 {
1715 //void overcomboblocktranslucent(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h, int32_t opacity)
1716 overcomboblocktranslucent(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1, 128);
1717
1718 }
1719 else
1720 {
1721 //overcomboblock(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h)
1722 overcomboblock(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1);
1723 }
1724 }
1725 }
1726
1727
1728
1729
1730 void do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1731 {
1732 //broken 2.50.2 and earlier drawcharacter()
1733 if ( get_bit(quest_rules, qr_BROKENCHARINTDRAWING) )
1734 {
1735 //sdci[1]=layer
1736 //sdci[2]=x
1737 //sdci[3]=y
1738 //sdci[4]=font
1739 //sdci[5]=color
1740 //sdci[6]=bg color
1741 //sdci[7]=strech x (width)
1742 //sdci[8]=stretch y (height)
1743 //sdci[9]=char
1744 //sdci[10]=opacity
1745
1746 int32_t x=sdci[2]/10000;
1747 int32_t y=sdci[3]/10000;
1748 int32_t font_index=sdci[4]/10000;
1749 int32_t color=sdci[5]/10000;
1750 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1751 int32_t w=sdci[7]/10000;
1752 int32_t h=sdci[8]/10000;
1753 char glyph=char(sdci[9]/10000);
1754 int32_t opacity=sdci[10]/10000;
1755
1756 //safe check
1757 if(bg_color < -1) bg_color = -1;
1758
1759 if(w>512) w=512; //w=vbound(w,0,512);
1760
1761 if(h>512) h=512; //h=vbound(h,0,512);
1762
1763 //undone
1764 if(w>0&&h>0)//stretch the character
1765 {
1766 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1767
1768 if(opacity < 128)
1769 {
1770 if(w>128||h>128)
1771 {
1772 clear_bitmap(prim_bmp);
1773
1774 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1775 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1776 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1777 }
1778 else //this is faster
1779 {
1780 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1781
1782 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1783 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1784 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1785
1786 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1787 }
1788 }
1789 else // no opacity
1790 {
1791 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1792 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1793 }
1794
1795 }
1796 else //no stretch
1797 {
1798 if(opacity < 128)
1799 {
1800 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1801 clear_bitmap(pbmp);
1802
1803 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1804 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1805
1806 destroy_bitmap(pbmp);
1807 }
1808 else // no opacity
1809 {
1810 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1811 }
1812 }
1813 }
1814
1815 else //2.53.0 fixed version and later.
1816 {
1817
1818 //sdci[1]=layer
1819 //sdci[2]=x
1820 //sdci[3]=y
1821 //sdci[4]=font
1822 //sdci[5]=color
1823 //sdci[6]=bg color
1824 //sdci[7]=strech x (width)
1825 //sdci[8]=stretch y (height)
1826 //sdci[9]=char
1827 //sdci[10]=opacity
1828
1829 int32_t x=sdci[2]/10000;
1830 int32_t y=sdci[3]/10000;
1831 int32_t font_index=sdci[4]/10000;
1832 int32_t color=sdci[5]/10000;
1833 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1834 int32_t w=sdci[7]/10000;
1835 int32_t h=sdci[8]/10000;
1836 char glyph=char(sdci[9]/10000);
1837 int32_t opacity=sdci[10]/10000;
1838
1839 //safe check
1840 if(bg_color < -1) bg_color = -1;
1841
1842 if(w>512) w=512; //w=vbound(w,0,512);
1843
1844 if(h>512) h=512; //h=vbound(h,0,512);
1845
1846 //undone
1847 if(w>0&&h>0)//stretch the character
1848 {
1849 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1850
1851 if(opacity < 128)
1852 {
1853 if(w>128||h>128)
1854 {
1855 clear_bitmap(prim_bmp);
1856
1857 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1858 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1859 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1860 }
1861 else //this is faster
1862 {
1863 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1864
1865 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1866 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1867 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1868
1869 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1870 }
1871 }
1872 else // no opacity
1873 {
1874 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1875 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1876 }
1877
1878 }
1879 else //no stretch
1880 {
1881 if(opacity < 128)
1882 {
1883 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1884 clear_bitmap(pbmp);
1885
1886 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1887 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1888
1889 destroy_bitmap(pbmp);
1890 }
1891 else // no opacity
1892 {
1893 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1894 }
1895 }
1896
1897 }
1898
1899 }
1900
1901
1902 void do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1903 {
1904 //broken 2.50.2 and earlier drawinteger()
1905 if ( get_bit(quest_rules, qr_BROKENCHARINTDRAWING) )
1906 {
1907 //sdci[1]=layer
1908 //sdci[2]=x
1909 //sdci[3]=y
1910 //sdci[4]=font
1911 //sdci[5]=color
1912 //sdci[6]=bg color
1913 //sdci[7]=strech x (width)
1914 //sdci[8]=stretch y (height)
1915 //sdci[9]=integer
1916 //sdci[10]=num decimal places
1917 //sdci[11]=opacity
1918
1919 int32_t x=sdci[2]/10000;
1920 int32_t y=sdci[3]/10000;
1921 int32_t font_index=sdci[4]/10000;
1922 int32_t color=sdci[5]/10000;
1923 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1924 int32_t w=sdci[7]/10000;
1925 int32_t h=sdci[8]/10000;
1926 //float number=static_cast<float>(sdci[9])/10000.0f;
1927 int32_t decplace=sdci[10]/10000;
1928 int32_t opacity=sdci[11]/10000;
1929
1930 //safe check
1931 if(bg_color < -1) bg_color = -1;
1932
1933 if(w>512) w=512; //w=vbound(w,0,512);
1934
1935 if(h>512) h=512; //h=vbound(h,0,512);
1936
1937 char numbuf[15];
1938
1939 switch(decplace)
1940 {
1941 default:
1942 case 0:
1943 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1944 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1945
1946 case 1:
1947 //sprintf(numbuf,"%.01f",number);
1948 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1949 break;
1950
1951 case 2:
1952 //sprintf(numbuf,"%.02f",number);
1953 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1954 break;
1955
1956 case 3:
1957 //sprintf(numbuf,"%.03f",number);
1958 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1959 break;
1960
1961 case 4:
1962 //sprintf(numbuf,"%.04f",number);
1963 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1964 break;
1965 }
1966
1967 if(w>0&&h>0)//stretch
1968 {
1969 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1970
1971 if(opacity < 128)
1972 {
1973 if(w>128||h>128)
1974 {
1975 clear_bitmap(prim_bmp);
1976
1977 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1978 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1979 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1980 }
1981 else
1982 {
1983 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
1984 clear_bitmap(pbmp2);
1985
1986 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1987 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1988 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1989
1990 destroy_bitmap(pbmp2);
1991 }
1992 }
1993 else // no opacity
1994 {
1995 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1996 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1997 }
1998
1999 }
2000 else //no stretch
2001 {
2002 if(opacity < 128)
2003 {
2004 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
2005 clear_bitmap(pbmp);
2006
2007 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
2008 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2009
2010 destroy_bitmap(pbmp);
2011 }
2012 else // no opacity
2013 {
2014 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
2015 }
2016 }
2017
2018 }
2019
2020 else //2.53.0 fixed version and later.
2021 {
2022 //sdci[1]=layer
2023 //sdci[2]=x
2024 //sdci[3]=y
2025 //sdci[4]=font
2026 //sdci[5]=color
2027 //sdci[6]=bg color
2028 //sdci[7]=strech x (width)
2029 //sdci[8]=stretch y (height)
2030 //sdci[9]=integer
2031 //sdci[10]=num decimal places
2032 //sdci[11]=opacity
2033
2034 int32_t x=sdci[2]/10000;
2035 int32_t y=sdci[3]/10000;
2036 int32_t font_index=sdci[4]/10000;
2037 int32_t color=sdci[5]/10000;
2038 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2039 int32_t w=sdci[7]/10000;
2040 int32_t h=sdci[8]/10000;
2041 //float number=static_cast<float>(sdci[9])/10000.0f;
2042 //int32_t numberint = sdci[9]/10000;
2043 int32_t decplace=sdci[10]/10000;
2044 int32_t opacity=sdci[11]/10000;
2045
2046 //safe check
2047 if(bg_color < -1) bg_color = -1;
2048
2049 if(w>512) w=512; //w=vbound(w,0,512);
2050
2051 if(h>512) h=512; //h=vbound(h,0,512);
2052
2053 char numbuf[15];
2054
2055 switch(decplace)
2056 {
2057 default:
2058 case 0:
2059 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
2060 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
2061
2062 case 1:
2063 //sprintf(numbuf,"%.01f",number);
2064 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
2065 break;
2066
2067 case 2:
2068 //sprintf(numbuf,"%.02f",number);
2069 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
2070 break;
2071
2072 case 3:
2073 //sprintf(numbuf,"%.03f",number);
2074 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
2075 break;
2076
2077 case 4:
2078 //sprintf(numbuf,"%.04f",number);
2079 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
2080 break;
2081 }
2082
2083 //FONT* font=get_zc_font(sdci[4]/10000);
2084
2085 if(w>0&&h>0)//stretch
2086 {
2087 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
2088 clear_bitmap(pbmp);
2089 //script_drawing_commands.GetSmallTextureBitmap(1,1);
2090
2091 if(opacity < 128)
2092 {
2093 if(w>128||h>128)
2094 {
2095 clear_bitmap(prim_bmp);
2096
2097 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
2098 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
2099 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
2100 }
2101 else
2102 {
2103 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
2104 clear_bitmap(pbmp2);
2105
2106 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
2107 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
2108 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
2109
2110 destroy_bitmap(pbmp2);
2111 }
2112 }
2113 else // no opacity
2114 {
2115 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
2116 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
2117 }
2118
2119 }
2120 else //no stretch
2121 {
2122 if(opacity < 128)
2123 {
2124 FONT* font = get_zc_font(font_index);
2125 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
2126 clear_bitmap(pbmp);
2127
2128 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
2129 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2130
2131 destroy_bitmap(pbmp);
2132 }
2133 else // no opacity
2134 {
2135 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
2136 }
2137 }
2138 }
2139 }
2140
2141
2142 1902 void do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2143 {
2144 //sdci[1]=layer
2145 //sdci[2]=x
2146 //sdci[3]=y
2147 //sdci[4]=font
2148 //sdci[5]=color
2149 //sdci[6]=bg color
2150 //sdci[7]=format_option
2151 //sdci[8]=string
2152 //sdci[9]=opacity
2153
2154 1902 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2155
2156
1/2
✓ Branch 0 taken 1902 times.
✗ Branch 1 not taken.
1902 if(!str)
2157 {
2158 al_trace("String pointer is null! Internal error. \n");
2159 return;
2160 }
2161
2162 1902 int32_t x=sdci[2]/10000;
2163 1902 int32_t y=sdci[3]/10000;
2164 1902 FONT* font=get_zc_font(sdci[4]/10000);
2165 1902 int32_t color=sdci[5]/10000;
2166 1902 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2167 1902 int32_t format_type=sdci[7]/10000;
2168 1902 int32_t opacity=sdci[9]/10000;
2169 //sdci[8] not needed :)
2170
2171 //safe check
2172
1/2
✓ Branch 0 taken 1902 times.
✗ Branch 1 not taken.
1902 if(bg_color < -1) bg_color = -1;
2173
2174
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1902 times.
1902 if(opacity < 128)
2175 {
2176 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2177 if (width < 1) return; //SANITY -Em
2178 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2179 clear_bitmap(pbmp);
2180 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2181 if(format_type == 2) // right-sided text
2182 x-=width;
2183 else if(format_type == 1) // centered text
2184 x-=width/2;
2185 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2186 destroy_bitmap(pbmp);
2187 }
2188 else // no opacity
2189 {
2190
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1902 times.
1902 if(format_type == 2) // right-sided text
2191 {
2192 textout_right_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2193 }
2194
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1902 times.
1902 else if(format_type == 1) // centered text
2195 {
2196 textout_centre_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2197 }
2198 else // standard left-sided text
2199 {
2200 1902 textout_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2201 }
2202 }
2203 1902 }
2204
2205 18817 void do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2206 {
2207 //sdci[1]=layer
2208 //sdci[2]=x
2209 //sdci[3]=y
2210 //sdci[4]=font
2211 //sdci[5]=color
2212 //sdci[6]=bg color
2213 //sdci[7]=format_option
2214 //sdci[8]=string
2215 //sdci[9]=opacity
2216 //sdci[10]=shadowtype
2217 //sdci[11]=shadow_color
2218
2219 18817 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2220
2221
1/2
✓ Branch 0 taken 18817 times.
✗ Branch 1 not taken.
18817 if(!str)
2222 {
2223 al_trace("String pointer is null! Internal error. \n");
2224 return;
2225 }
2226
2227 18817 int32_t x=sdci[2]/10000;
2228 18817 int32_t y=sdci[3]/10000;
2229 18817 FONT* font=get_zc_font(sdci[4]/10000);
2230 18817 int32_t color=sdci[5]/10000;
2231 18817 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2232 18817 int32_t format_type=sdci[7]/10000;
2233 18817 int32_t opacity=sdci[9]/10000;
2234 18817 int32_t textstyle = sdci[10]/10000;
2235 18817 int32_t shadow_color = sdci[11]/10000;
2236 //sdci[8] not needed :)
2237
2238 //safe check
2239
1/2
✓ Branch 0 taken 18817 times.
✗ Branch 1 not taken.
18817 if(bg_color < -1) bg_color = -1;
2240
2241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18817 times.
18817 if(opacity < 128)
2242 {
2243 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2244 if (width < 1) return; //SANITY -Em
2245 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2246 clear_bitmap(pbmp);
2247 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
2248 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2249 if(format_type == 2) // right-sided text
2250 x-=width;
2251 else if(format_type == 1) // centered text
2252 x-=width/2;
2253 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2254 destroy_bitmap(pbmp);
2255 }
2256 else // no opacity
2257 {
2258 18817 textout_styled_aligned_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
2259 }
2260 18817 }
2261
2262
2263 void do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2264 {
2265 //sdci[1]=layer
2266 //sdci[2]=x1
2267 //sdci[3]=y1
2268 //sdci[4]=x2
2269 //sdci[5]=y2
2270 //sdci[6]=x3
2271 //sdci[7]=y3
2272 //sdci[8]=x4
2273 //sdci[9]=y4
2274 //sdci[10]=width
2275 //sdci[11]=height
2276 //sdci[12]=cset
2277 //sdci[13]=flip
2278 //sdci[14]=tile/combo
2279 //sdci[15]=polytype
2280
2281 int32_t x1 = sdci[2]/10000;
2282 int32_t y1 = sdci[3]/10000;
2283 int32_t x2 = sdci[4]/10000;
2284 int32_t y2 = sdci[5]/10000;
2285 int32_t x3 = sdci[6]/10000;
2286 int32_t y3 = sdci[7]/10000;
2287 int32_t x4 = sdci[8]/10000;
2288 int32_t y4 = sdci[9]/10000;
2289 int32_t w = sdci[10]/10000;
2290 int32_t h = sdci[11]/10000;
2291 int32_t color = sdci[12]/10000;
2292 int32_t flip=(sdci[13]/10000)&3;
2293 int32_t tile = sdci[14]/10000;
2294 int32_t polytype = sdci[15]/10000;
2295
2296 //todo: finish palette shading
2297 /*
2298 POLYTYPE_FLAT
2299 POLYTYPE_GCOL
2300 POLYTYPE_GRGB
2301 POLYTYPE_ATEX
2302 POLYTYPE_PTEX
2303 POLYTYPE_ATEX_MASK
2304 POLYTYPE_PTEX_MASK
2305 POLYTYPE_ATEX_LIT
2306 POLYTYPE_PTEX_LIT
2307 POLYTYPE_ATEX_MASK_LIT
2308 POLYTYPE_PTEX_MASK_LIT
2309 POLYTYPE_ATEX_TRANS
2310 POLYTYPE_PTEX_TRANS
2311 POLYTYPE_ATEX_MASK_TRANS
2312 POLYTYPE_PTEX_MASK_TRANS
2313 */
2314 polytype = vbound(polytype, 0, 14);
2315
2316 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2317 {
2318 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2319 return; //non power of two error
2320 }
2321
2322 int32_t tex_width = w*16;
2323 int32_t tex_height = h*16;
2324
2325 BITMAP *tex;
2326
2327 bool mustDestroyBmp = false;
2328
2329 if ( tile > 65519 ) tex = zscriptDrawingRenderTarget->GetBitmapPtr(tile - 65519);
2330 else tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2331
2332 if(!tex)
2333 {
2334 mustDestroyBmp = true;
2335 tex = create_bitmap_ex(8, tex_width, tex_height);
2336 clear_bitmap(tex);
2337 }
2338
2339 int32_t col[4];
2340 /*
2341 if( color < 0 )
2342 {
2343 col[0]=draw_container.color_buffer[0];
2344 col[1]=draw_container.color_buffer[1];
2345 col[2]=draw_container.color_buffer[2];
2346 col[3]=draw_container.color_buffer[3];
2347 }
2348 else */
2349 {
2350 col[0]=col[1]=col[2]=col[3]=color;
2351 }
2352
2353 if(tile > 0 && tile <= 65519) // TILE
2354 {
2355 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2356 }
2357
2358 if ( tile < 0 ) // COMBO
2359 {
2360 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
2361 const int32_t tiletodraw = combo_tile(c, x1, y1);
2362 flip = flip ^ c.flip;
2363
2364 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2365 }
2366
2367 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2368 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2369 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2370 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(tex_width), 0, col[3] };
2371
2372 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
2373
2374 if(mustDestroyBmp)
2375 destroy_bitmap(tex);
2376
2377 }
2378
2379
2380 void do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2381 {
2382 //sdci[1]=layer
2383 //sdci[2]=x1
2384 //sdci[3]=y1
2385 //sdci[4]=x2
2386 //sdci[5]=y2
2387 //sdci[6]=x3
2388 //sdci[7]=y3
2389 //sdci[8]=width
2390 //sdci[9]=height
2391 //sdci[10]=cset
2392 //sdci[11]=flip
2393 //sdci[12]=tile/combo
2394 //sdci[13]=polytype
2395
2396 int32_t x1 = sdci[2]/10000;
2397 int32_t y1 = sdci[3]/10000;
2398 int32_t x2 = sdci[4]/10000;
2399 int32_t y2 = sdci[5]/10000;
2400 int32_t x3 = sdci[6]/10000;
2401 int32_t y3 = sdci[7]/10000;
2402 int32_t w = sdci[8]/10000;
2403 int32_t h = sdci[9]/10000;
2404 int32_t color = sdci[10]/10000;
2405 int32_t flip=(sdci[11]/10000)&3;
2406 int32_t tile = sdci[12]/10000;
2407 int32_t polytype = sdci[13]/10000;
2408
2409 polytype = vbound(polytype, 0, 14);
2410
2411 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2412 {
2413 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2414 return; //non power of two error
2415 }
2416
2417 int32_t tex_width = w*16;
2418 int32_t tex_height = h*16;
2419
2420 bool mustDestroyBmp = false;
2421 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2422
2423 if(!tex)
2424 {
2425 mustDestroyBmp = true;
2426 tex = create_bitmap_ex(8, tex_width, tex_height);
2427 clear_bitmap(tex);
2428 }
2429
2430 int32_t col[3];
2431 /*
2432 if( color < 0 )
2433 {
2434 col[0]=draw_container.color_buffer[0];
2435 col[1]=draw_container.color_buffer[1];
2436 col[2]=draw_container.color_buffer[2];
2437 }
2438 else */
2439 {
2440 col[0]=col[1]=col[2]=color;
2441 }
2442
2443 if(tile > 0) // TILE
2444 {
2445 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2446 }
2447 else // COMBO
2448 {
2449 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
2450 const int32_t tiletodraw = combo_tile(c, x1, y1);
2451 flip = flip ^ c.flip;
2452
2453 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2454 }
2455
2456 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2457 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2458 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2459
2460
2461 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
2462
2463 if(mustDestroyBmp)
2464 destroy_bitmap(tex);
2465 }
2466
2467
2468 void do_drawbitmapr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2469 {
2470 //sdci[1]=layer
2471 //sdci[2]=bitmap
2472 //sdci[3]=sourcex
2473 //sdci[4]=sourcey
2474 //sdci[5]=sourcew
2475 //sdci[6]=sourceh
2476 //sdci[7]=destx
2477 //sdci[8]=desty
2478 //sdci[9]=destw
2479 //sdci[10]=desth
2480 //sdci[11]=rotation
2481 //sdci[12]=mask
2482
2483 int32_t bitmapIndex = sdci[2]/10000;
2484 int32_t sx = sdci[3]/10000;
2485 int32_t sy = sdci[4]/10000;
2486 int32_t sw = sdci[5]/10000;
2487 int32_t sh = sdci[6]/10000;
2488 int32_t dx = sdci[7]/10000;
2489 int32_t dy = sdci[8]/10000;
2490 int32_t dw = sdci[9]/10000;
2491 int32_t dh = sdci[10]/10000;
2492 float rot = sdci[11]/10000;
2493 bool masked = (sdci[12] != 0);
2494
2495 //bugfix
2496 sx = vbound(sx, 0, 512);
2497 sy = vbound(sy, 0, 512);
2498 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2499 sh = vbound(sh, 0, 512 - sy);
2500
2501
2502 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2503 return;
2504
2505 bool stretched = (sw != dw || sh != dh);
2506
2507 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2508
2509 if(!sourceBitmap)
2510 {
2511 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2512 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2513 return;
2514 }
2515
2516 BITMAP* subBmp = 0;
2517
2518 if(rot != 0)
2519 {
2520 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2521
2522 if(!subBmp)
2523 {
2524 Z_scripterrlog("DrawBitmap() failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2525 return;
2526 }
2527 }
2528
2529
2530 dx = dx + xoffset;
2531 dy = dy + yoffset;
2532
2533 if(stretched)
2534 {
2535 if(masked)
2536 {
2537 if(rot != 0)
2538 {
2539 //if ( rot == 4096 ) { //translucent
2540 // masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2541 // //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2542 // draw_trans_sprite(bmp, subBmp, dx, dy);
2543 // //draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, 0);
2544
2545
2546 // }
2547 //else {
2548 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2549 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2550 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2551 //
2552
2553 // }
2554 }
2555 else
2556 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2557 }
2558 else
2559 {
2560 if(rot != 0)
2561 {
2562 //if ( rot == 4096 ) { //translucent
2563 // stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2564 // draw_trans_sprite(bmp, subBmp, dx, dy);
2565 // }
2566 //else {
2567 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2568 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2569 // }
2570 }
2571 else
2572 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2573 }
2574 }
2575 else
2576 {
2577 if(masked)
2578 {
2579 if(rot != 0)
2580 {
2581 //if ( rot == 4096 ) {//translucent
2582 // masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2583 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2584
2585 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2586 //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2587 // draw_trans_sprite(bmp, subBmp, dx, dy);
2588 // }
2589 //else {
2590 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2591 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2592 // }
2593 }
2594 else
2595 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2596 }
2597 else
2598 {
2599 if(rot != 0)
2600 {
2601 //if ( rot == 4096 ) { //translucent
2602 // blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2603 // draw_trans_sprite(bmp, subBmp, dx, dy);
2604 // }
2605 //else {
2606 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2607 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2608 // }
2609 }
2610 else
2611 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2612 }
2613 }
2614
2615 //cleanup
2616 if(subBmp)
2617 {
2618 script_drawing_commands.ReleaseSubBitmap(subBmp);
2619 }
2620 }
2621
2622
2623 //Draw]()
2624 void do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2625 {
2626 /*
2627 //sdci[1]=layer
2628 //sdci[2]=bitmap
2629 //sdci[3]=sourcex
2630 //sdci[4]=sourcey
2631 //sdci[5]=sourcew
2632 //sdci[6]=sourceh
2633 //sdci[7]=destx
2634 //sdci[8]=desty
2635 //sdci[9]=destw
2636 //sdci[10]=desth
2637 //sdci[11]=rotation/angle
2638 //scdi[12] = pivot cx
2639 //sdci[13] = pivot cy
2640 //scdi[14] = effect flags
2641
2642
2643 const int32_t BITDX_NORMAL = 0;
2644 const int32_t BITDX_TRANS = 1; //Translucent
2645 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
2646 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
2647 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
2648 //Note: Some modes cannot be combined. if a combination is not supported, an error
2649 // detailing this will be shown in allegro.log.
2650
2651 //scdi[15] = litcolour
2652 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2653 /not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2654
2655 //sdci[16]=mask
2656
2657 */
2658
2659 int32_t bitmapIndex = sdci[2]/10000;
2660 int32_t sx = sdci[3]/10000;
2661 int32_t sy = sdci[4]/10000;
2662 int32_t sw = sdci[5]/10000;
2663 int32_t sh = sdci[6]/10000;
2664 int32_t dx = sdci[7]/10000;
2665 int32_t dy = sdci[8]/10000;
2666 int32_t dw = sdci[9]/10000;
2667 int32_t dh = sdci[10]/10000;
2668 float rot = sdci[11]/10000;
2669 int32_t cx = sdci[12]/10000;
2670 int32_t cy = sdci[13]/10000;
2671 int32_t mode = sdci[14]/10000;
2672 int32_t litcolour = sdci[15]/10000;
2673 bool masked = (sdci[16] != 0);
2674
2675
2676
2677 //bugfix
2678 sx = vbound(sx, 0, 512);
2679 sy = vbound(sy, 0, 512);
2680 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2681 sh = vbound(sh, 0, 512 - sy);
2682
2683
2684 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2685 return;
2686
2687 bool stretched = (sw != dw || sh != dh);
2688
2689 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2690
2691 if(!sourceBitmap)
2692 {
2693 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2694 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2695 return;
2696 }
2697
2698 BITMAP* subBmp = 0;
2699
2700 /*
2701 if ( bitmapIndex == -1 ) {
2702 blit(bmp, sourceBitmap, sx, sy, 0, 0, dw, dh);
2703 }
2704 */
2705
2706 if(rot != 0 || mode != 0)
2707 {
2708 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2709
2710 if(!subBmp)
2711 {
2712 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2713 return;
2714 }
2715 }
2716
2717
2718 dx = dx + xoffset;
2719 dy = dy + yoffset;
2720
2721 if(stretched)
2722 {
2723 if(masked) //stretched and masked
2724 {
2725 if ( rot == 0 ) //if not rotated
2726 {
2727 switch(mode)
2728 {
2729 case 1:
2730 //transparent
2731 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2732 draw_trans_sprite(bmp, subBmp, dx, dy);
2733 break;
2734
2735
2736 case 2:
2737 //pivot?
2738 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2739 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2740 //Pivoting requires two more args
2741 break;
2742
2743 case 3:
2744 //pivot + trans
2745 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2746 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2747 break;
2748
2749 case 4:
2750 //flip v
2751 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2752 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2753 break;
2754
2755 case 5:
2756 //trans + v flip
2757 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2758 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2759 break;
2760
2761 case 6:
2762 //pivot + v flip
2763 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2764 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2765 break;
2766
2767 case 8:
2768 //vlip h
2769 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2770 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2771 break;
2772
2773 case 9:
2774 //trans + h flip
2775 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2776 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2777 break;
2778
2779 case 10:
2780 //flip H and pivot
2781 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2782 //return error cannot pivot and h flip
2783 break;
2784
2785 case 12:
2786 //vh flip
2787 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2788 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2789 break;
2790
2791 case 13:
2792 //trans + vh flip
2793 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2794 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2795 break;
2796
2797 case 14:
2798 //pivot and vh flip
2799 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2800 //return error cannot both pivot and vh flip
2801 break;
2802
2803 case 16:
2804 //lit
2805 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2806 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2807 break;
2808
2809 case 18:
2810 //pivot, lit
2811 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2812 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2813 break;
2814
2815 case 20:
2816 //lit + v flip
2817 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2818 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
2819 break;
2820
2821 case 22:
2822 //Pivot, vflip, lit
2823 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2824 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2825 break;
2826
2827 case 24:
2828 //lit + h flip
2829 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2830 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
2831 break;
2832
2833 case 26:
2834 //pivot + lit + hflip
2835 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
2836 //return error cannot pivot, lit, and flip
2837 break;
2838
2839 case 28:
2840 //lit + vh flip
2841 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2842 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
2843 break;
2844
2845 case 32: //gouraud
2846 //Probably not wort supporting.
2847 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2848 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2849 break;
2850
2851 case 0:
2852 //no effect
2853 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2854 break;
2855
2856
2857 default:
2858 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2859
2860
2861 }
2862 } //end if not rotated
2863
2864 if ( rot != 0 ) //if rotated
2865 {
2866 switch(mode)
2867 {
2868 case 1:
2869 //transparent
2870 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2871 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2872
2873 break;
2874
2875 case 2:
2876 //pivot?
2877 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2878 //return an error, cannot both rotate and pivot
2879 break;
2880
2881 case 3:
2882 //pivot + trans
2883 //return an error, cannot both rotate and pivot
2884 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2885 break;
2886
2887 case 4:
2888 //flip v
2889 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2890 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2891 break;
2892
2893 case 5:
2894 //trans + v flip
2895 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2896 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2897 break;
2898
2899 case 6:
2900 //pivot + v flip
2901 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2902 //return an error, cannot both rotate and pivot
2903 break;
2904
2905 case 8:
2906 //flip h
2907 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
2908 //return an error, cannot both rotate and flip H
2909 break;
2910
2911 case 9:
2912 //trans + h flip
2913 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
2914 //return an error, cannot rotate and flip a trans sprite
2915 break;
2916
2917 case 10:
2918 //flip H and pivot
2919 //return error cannot pivot and h flip
2920 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2921 break;
2922
2923 case 12:
2924 //vh flip
2925 //return an error, cannot rotate and VH flip a trans sprite
2926 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2927 break;
2928
2929 case 13:
2930 //trans + vh flip
2931 //return an error, cannot rotate and VH flip a trans sprite
2932 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2933 break;
2934
2935 case 14:
2936 //pivot and vh flip
2937 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2938 //return error cannot both pivot and vh flip
2939 break;
2940
2941 case 16:
2942 //lit
2943 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2944 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2945 break;
2946
2947 case 18:
2948 //pivot, lit
2949 //return an error, cannot both rotate and pivot
2950 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2951 break;
2952
2953 case 20:
2954 //lit + vflip
2955 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2956 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2957 break;
2958
2959 case 22:
2960 //Pivot, vflip, lit
2961 //return an error, cannot both rotate and pivot
2962 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2963 break;
2964
2965 case 24:
2966 //lit + h flip
2967 //return an error, cannot both rotate and H flip
2968 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
2969 break;
2970
2971 case 26:
2972 //pivot + lit + hflip
2973 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
2974 //return error cannot pivot, lit, and flip
2975 break;
2976
2977 case 28:
2978 //lit + vh flip
2979 //return an error, cannot both rotate and VH flip
2980 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2981 break;
2982
2983 case 32: //gouraud
2984 //Probably not wort supporting.
2985 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2986 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2987 break;
2988
2989 case 0:
2990 //no effect.
2991 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2992 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2993 break;
2994
2995 default:
2996 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2997
2998 }
2999 }
3000 } //end if stretched and masked
3001
3002 else //stretched, not masked
3003 {
3004 if ( rot == 0 ) //if not rotated
3005 {
3006 switch(mode) {
3007 case 1:
3008 //transparent
3009 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3010 draw_trans_sprite(bmp, subBmp, dx, dy);
3011 break;
3012
3013
3014 case 2:
3015 //pivot?
3016 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3017 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3018 //Pivoting requires two more args
3019 break;
3020
3021 case 3:
3022 //pivot + trans
3023 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3024 pivot_sprite_trans(bmp, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
3025 break;
3026
3027 case 4:
3028 //flip v
3029 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3030 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3031 break;
3032
3033 case 5:
3034 //trans + v flip
3035 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3036 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3037 break;
3038
3039 case 6:
3040 //pivot + v flip
3041 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3042 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3043 break;
3044
3045 case 8:
3046 //vlip h
3047 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3048 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3049 break;
3050
3051 case 9:
3052 //trans + h flip
3053 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3054 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3055 break;
3056
3057 case 10:
3058 //flip H and pivot
3059 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3060 //return error cannot pivot and h flip
3061 break;
3062
3063 case 12:
3064 //vh flip
3065 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3066 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3067 break;
3068
3069 case 13:
3070 //trans + vh flip
3071 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3072 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3073 break;
3074
3075 case 14:
3076 //pivot and vh flip
3077 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3078 //return error cannot both pivot and vh flip
3079 break;
3080
3081 case 16:
3082 //lit
3083 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3084 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3085 break;
3086
3087 case 18:
3088 //pivot, lit
3089 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3090 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3091 break;
3092
3093 case 20:
3094 //lit + v flip
3095 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3096 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3097 break;
3098
3099 case 22:
3100 //Pivot, vflip, lit
3101 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3102 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3103 break;
3104
3105 case 24:
3106 //lit + h flip
3107 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3108 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3109 break;
3110
3111 case 26:
3112 //pivot + lit + hflip
3113 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3114 //return error cannot pivot, lit, and flip
3115 break;
3116
3117 case 28:
3118 //lit + vh flip
3119 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3120 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3121 break;
3122
3123 case 32: //gouraud
3124 //Probably not wort supporting.
3125 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3126 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3127 break;
3128
3129 case 0:
3130 //no effect
3131 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
3132 break;
3133
3134
3135 default:
3136 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3137
3138
3139 }
3140 } //end if not rotated
3141
3142 if ( rot != 0 ) //if rotated
3143 {
3144 switch(mode)
3145 {
3146 case 1:
3147 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3148 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3149
3150 break;
3151
3152 case 2:
3153 //pivot?
3154 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3155 //return an error, cannot both rotate and pivot
3156 break;
3157
3158 case 3:
3159 //pivot + trans
3160 //return an error, cannot both rotate and pivot
3161 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3162 break;
3163
3164 case 4:
3165 //flip v
3166 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3167 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3168 break;
3169
3170 case 5:
3171 //trans + v flip
3172 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3173 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3174 break;
3175
3176 case 6:
3177 //pivot + v flip
3178 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3179 //return an error, cannot both rotate and pivot
3180 break;
3181
3182 case 8:
3183 //flip h
3184 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3185 //return an error, cannot both rotate and flip H
3186 break;
3187
3188 case 9:
3189 //trans + h flip
3190 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3191 //return an error, cannot rotate and flip a trans sprite
3192 break;
3193
3194 case 10:
3195 //flip H and pivot
3196 //return error cannot pivot and h flip
3197 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3198 break;
3199
3200 case 12:
3201 //vh flip
3202 //return an error, cannot rotate and VH flip a trans sprite
3203 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3204 break;
3205
3206 case 13:
3207 //trans + vh flip
3208 //return an error, cannot rotate and VH flip a trans sprite
3209 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3210 break;
3211
3212 case 14:
3213 //pivot and vh flip
3214 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3215 //return error cannot both pivot and vh flip
3216 break;
3217
3218 case 16:
3219 //lit
3220 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3221 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3222 break;
3223
3224 case 18:
3225 //pivot, lit
3226 //return an error, cannot both rotate and pivot
3227 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3228 break;
3229
3230 case 20:
3231 //lit + vflip
3232 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3233 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3234 break;
3235
3236 case 22:
3237 //Pivot, vflip, lit
3238 //return an error, cannot both rotate and pivot
3239 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3240 break;
3241
3242 case 24:
3243 //lit + h flip
3244 //return an error, cannot both rotate and H flip
3245 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3246 break;
3247
3248 case 26:
3249 //pivot + lit + hflip
3250 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3251 //return error cannot pivot, lit, and flip
3252 break;
3253
3254 case 28:
3255 //lit + vh flip
3256 //return an error, cannot both rotate and VH flip
3257 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3258 break;
3259
3260 case 32: //gouraud
3261 //Probably not wort supporting.
3262 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3263 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3264 break;
3265
3266 case 0:
3267 //no effect.
3268 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3269 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3270 break;
3271
3272 default:
3273 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3274
3275 }
3276 }
3277
3278 } //end if stretched, but not masked
3279 }
3280 else //not stretched
3281 {
3282
3283 if(masked) //if masked, but not stretched
3284 {
3285
3286 if ( rot == 0 ) //if not rotated
3287 {
3288 switch(mode)
3289 {
3290 case 1:
3291 //transparent
3292 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3293 draw_trans_sprite(bmp, subBmp, dx, dy);
3294 break;
3295
3296
3297 case 2:
3298 //pivot?
3299 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3300 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3301 //Pivoting requires two more args
3302 break;
3303
3304 case 3:
3305 //pivot + trans
3306 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3307 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3308 break;
3309
3310 case 4:
3311 //flip v
3312 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3313 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3314 break;
3315
3316 case 5:
3317 //trans + v flip
3318 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3319 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3320 break;
3321
3322 case 6:
3323 //pivot + v flip
3324 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3325 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3326 break;
3327
3328 case 8:
3329 //vlip h
3330 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3331 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3332 break;
3333
3334 case 9:
3335 //trans + h flip
3336 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3337 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3338 break;
3339
3340 case 10:
3341 //flip H and pivot
3342 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3343 //return error cannot pivot and h flip
3344 break;
3345
3346 case 12:
3347 //vh flip
3348 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3349 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3350 break;
3351
3352 case 13:
3353 //trans + vh flip
3354 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3355 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3356 break;
3357
3358 case 14:
3359 //pivot and vh flip
3360 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3361 //return error cannot both pivot and vh flip
3362 break;
3363
3364 case 16:
3365 //lit
3366 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3367 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3368 break;
3369
3370 case 18:
3371 //pivot, lit
3372 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3373 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3374 break;
3375
3376 case 20:
3377 //lit + v flip
3378 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3379 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3380 break;
3381
3382 case 22:
3383 //Pivot, vflip, lit
3384 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3385 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3386 break;
3387
3388 case 24:
3389 //lit + h flip
3390 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3391 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3392 break;
3393
3394 case 26:
3395 //pivot + lit + hflip
3396 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3397 //return error cannot pivot, lit, and flip
3398 break;
3399
3400 case 28:
3401 //lit + vh flip
3402 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3403 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3404 break;
3405
3406 case 32: //gouraud
3407 //Probably not wort supporting.
3408 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3409 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3410 break;
3411
3412 case 0:
3413 //no effect
3414 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3415 break;
3416
3417
3418 default:
3419 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3420
3421
3422 }
3423 } //end if not rotated
3424
3425 if ( rot != 0 ) //if rotated
3426 {
3427 switch(mode)
3428 {
3429 case 1:
3430 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //transparent
3431 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3432
3433 break;
3434
3435 case 2:
3436 //pivot?
3437 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3438 //return an error, cannot both rotate and pivot
3439 break;
3440
3441 case 3:
3442 //pivot + trans
3443 //return an error, cannot both rotate and pivot
3444 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3445 break;
3446
3447 case 4:
3448 //flip v
3449 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3450 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3451 break;
3452
3453 case 5:
3454 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
3455 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3456 break;
3457
3458 case 6:
3459 //pivot + v flip
3460 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3461 //return an error, cannot both rotate and pivot
3462 break;
3463
3464 case 8:
3465 //flip h
3466 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3467 //return an error, cannot both rotate and flip H
3468 break;
3469
3470 case 9:
3471 //trans + h flip
3472 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3473 //return an error, cannot rotate and flip a trans sprite
3474 break;
3475
3476 case 10:
3477 //flip H and pivot
3478 //return error cannot pivot and h flip
3479 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3480 break;
3481
3482 case 12:
3483 //vh flip
3484 //return an error, cannot rotate and VH flip a trans sprite
3485 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3486 break;
3487
3488 case 13:
3489 //trans + vh flip
3490 //return an error, cannot rotate and VH flip a trans sprite
3491 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3492 break;
3493
3494 case 14:
3495 //pivot and vh flip
3496 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3497 //return error cannot both pivot and vh flip
3498 break;
3499
3500 case 16:
3501 //lit
3502 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3503 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3504 break;
3505
3506 case 18:
3507 //pivot, lit
3508 //return an error, cannot both rotate and pivot
3509 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3510 break;
3511
3512 case 20:
3513 //lit + vflip
3514 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3515 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3516 break;
3517
3518 case 22:
3519 //Pivot, vflip, lit
3520 //return an error, cannot both rotate and pivot
3521 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3522 break;
3523
3524 case 24:
3525 //lit + h flip
3526 //return an error, cannot both rotate and H flip
3527 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3528 break;
3529
3530 case 26:
3531 //pivot + lit + hflip
3532 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3533 //return error cannot pivot, lit, and flip
3534 break;
3535
3536 case 28:
3537 //lit + vh flip
3538 //return an error, cannot both rotate and VH flip
3539 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3540 break;
3541
3542 case 32: //gouraud
3543 //Probably not wort supporting.
3544 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3545 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3546 break;
3547
3548 case 0:
3549 //no effect.
3550 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3551 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3552 break;
3553
3554 default:
3555 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3556
3557 }
3558 } //end rtated, masked
3559 } //end if masked
3560
3561 else //not masked, and not stretched; just blit
3562 {
3563
3564 if ( rot == 0 ) //if not rotated
3565 {
3566 switch(mode)
3567 {
3568 case 1:
3569 //transparent
3570 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3571 draw_trans_sprite(bmp, subBmp, dx, dy);
3572 break;
3573
3574
3575 case 2:
3576 //pivot?
3577 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3578 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3579 //Pivoting requires two more args
3580 break;
3581
3582 case 3:
3583 //pivot + trans
3584 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3585 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3586 break;
3587
3588 case 4:
3589 //flip v
3590 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3591 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3592 break;
3593
3594 case 5:
3595 //trans + v flip
3596 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3597 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3598 break;
3599
3600 case 6:
3601 //pivot + v flip
3602 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3603 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3604 break;
3605
3606 case 8:
3607 //vlip h
3608 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3609 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3610 break;
3611
3612 case 9:
3613 //trans + h flip
3614 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3615 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3616 break;
3617
3618 case 10:
3619 //flip H and pivot
3620 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3621 //return error cannot pivot and h flip
3622 break;
3623
3624 case 12:
3625 //vh flip
3626 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3627 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3628 break;
3629
3630 case 13:
3631 //trans + vh flip
3632 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3633 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3634 break;
3635
3636 case 14:
3637 //pivot and vh flip
3638 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3639 //return error cannot both pivot and vh flip
3640 break;
3641
3642 case 16:
3643 //lit
3644 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3645 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3646 break;
3647
3648 case 18:
3649 //pivot, lit
3650 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3651 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3652 break;
3653
3654 case 20:
3655 //lit + v flip
3656 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3657 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3658 break;
3659
3660 case 22:
3661 //Pivot, vflip, lit
3662 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3663 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3664 break;
3665
3666 case 24:
3667 //lit + h flip
3668 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3669 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3670 break;
3671
3672 case 26:
3673 //pivot + lit + hflip
3674 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3675 //return error cannot pivot, lit, and flip
3676 break;
3677
3678 case 28:
3679 //lit + vh flip
3680 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3681 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3682 break;
3683
3684 case 32: //gouraud
3685 //Probably not wort supporting.
3686 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3687 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3688 break;
3689
3690 case 0:
3691 //no effect
3692 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3693 break;
3694
3695
3696 default:
3697 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3698
3699
3700 }
3701 } //end if not rotated
3702
3703 if ( rot != 0 ) //if rotated
3704 {
3705 switch(mode)
3706 {
3707 case 1:
3708 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);//transparent
3709 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3710
3711 break;
3712
3713 case 2:
3714 //pivot?
3715 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3716 //return an error, cannot both rotate and pivot
3717 break;
3718
3719 case 3:
3720 //pivot + trans
3721 //return an error, cannot both rotate and pivot
3722 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3723 break;
3724
3725 case 4:
3726 //flip v
3727 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3728 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3729 break;
3730
3731 case 5:
3732 //trans + v flip
3733 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3734 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3735 break;
3736
3737 case 6:
3738 //pivot + v flip
3739 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3740 //return an error, cannot both rotate and pivot
3741 break;
3742
3743 case 8:
3744 //flip h
3745 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3746 //return an error, cannot both rotate and flip H
3747 break;
3748
3749 case 9:
3750 //trans + h flip
3751 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3752 //return an error, cannot rotate and flip a trans sprite
3753 break;
3754
3755 case 10:
3756 //flip H and pivot
3757 //return error cannot pivot and h flip
3758 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3759 break;
3760
3761 case 12:
3762 //vh flip
3763 //return an error, cannot rotate and VH flip a trans sprite
3764 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3765 break;
3766
3767 case 13:
3768 //trans + vh flip
3769 //return an error, cannot rotate and VH flip a trans sprite
3770 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3771 break;
3772
3773 case 14:
3774 //pivot and vh flip
3775 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3776 //return error cannot both pivot and vh flip
3777 break;
3778
3779 case 16:
3780 //lit
3781 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3782 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3783 break;
3784
3785 case 18:
3786 //pivot, lit
3787 //return an error, cannot both rotate and pivot
3788 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3789 break;
3790
3791 case 20:
3792 //lit + vflip
3793 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3794 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3795 break;
3796
3797 case 22:
3798 //Pivot, vflip, lit
3799 //return an error, cannot both rotate and pivot
3800 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3801 break;
3802
3803 case 24:
3804 //lit + h flip
3805 //return an error, cannot both rotate and H flip
3806 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3807 break;
3808
3809 case 26:
3810 //pivot + lit + hflip
3811 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3812 //return error cannot pivot, lit, and flip
3813 break;
3814
3815 case 28:
3816 //lit + vh flip
3817 //return an error, cannot both rotate and VH flip
3818 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3819 break;
3820
3821 case 32: //gouraud
3822 //Probably not wort supporting.
3823 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3824 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3825 break;
3826
3827 case 0:
3828 //no effect.
3829 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3830 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3831 break;
3832
3833 default:
3834 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3835
3836 }
3837 } //end if rotated
3838 } //end if not masked
3839 } //end if not stretched
3840
3841 //cleanup
3842 if(subBmp)
3843 {
3844 script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
3845 }
3846 }
3847
3848
3849 void do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3850 {
3851 //sdci[1]=layer
3852 //sdci[2]=pos[12]
3853 //sdci[3]=uv[8]
3854 //sdci[4]=color[4]
3855 //sdci[5]=size[2]
3856 //sdci[6]=flip
3857 //sdci[7]=tile/combo
3858 //sdci[8]=polytype
3859
3860 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3861
3862 if(!v_ptr)
3863 {
3864 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
3865 return;
3866 }
3867
3868 std::vector<int32_t> &v = *v_ptr;
3869
3870 if(v.empty())
3871 return;
3872
3873 int32_t* pos = &v[0];
3874 int32_t* uv = &v[12];
3875 int32_t* col = &v[20];
3876 int32_t* size = &v[24];
3877
3878 int32_t w = size[0]; //magic numerical constants... yuck.
3879 int32_t h = size[1];
3880 int32_t flip = (sdci[6]/10000)&3;
3881 int32_t tile = sdci[7]/10000;
3882 int32_t polytype = sdci[8]/10000;
3883
3884 polytype = vbound(polytype, 0, 14);
3885
3886 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3887 {
3888 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3889 return; //non power of two error
3890 }
3891
3892 int32_t tex_width = w*16;
3893 int32_t tex_height = h*16;
3894
3895 bool mustDestroyBmp = false;
3896 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3897
3898 if(!tex)
3899 {
3900 mustDestroyBmp = true;
3901 tex = create_bitmap_ex(8, tex_width, tex_height);
3902 clear_bitmap(tex);
3903 }
3904
3905 if(tile > 0) // TILE
3906 {
3907 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3908 }
3909 else // COMBO
3910 {
3911 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
3912 const int32_t tiletodraw = combo_tile(c, 0, 0);
3913 flip = flip ^ c.flip;
3914
3915 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3916 }
3917
3918 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3919 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3920 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3921 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
3922
3923 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
3924
3925 if(mustDestroyBmp)
3926 destroy_bitmap(tex);
3927
3928 }
3929
3930
3931
3932 void do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3933 {
3934 //sdci[1]=layer
3935 //sdci[2]=pos[9]
3936 //sdci[3]=uv[6]
3937 //sdci[4]=color[3]
3938 //sdci[5]=size[2]
3939 //sdci[6]=flip
3940 //sdci[7]=tile/combo
3941 //sdci[8]=polytype
3942
3943 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3944
3945 if(!v_ptr)
3946 {
3947 al_trace("Triange3d: Vector pointer is null! Internal error. \n");
3948 return;
3949 }
3950
3951 std::vector<int32_t> &v = *v_ptr;
3952
3953 if(v.empty())
3954 return;
3955
3956 int32_t* pos = &v[0];
3957 int32_t* uv = &v[9];
3958 int32_t* col = &v[15];
3959 int32_t* size = &v[18];
3960
3961 int32_t w = size[0]; //magic numerical constants... yuck.
3962 int32_t h = size[1];
3963 int32_t flip = (sdci[6]/10000)&3;
3964 int32_t tile = sdci[7]/10000;
3965 int32_t polytype = sdci[8]/10000;
3966
3967 polytype = vbound(polytype, 0, 14);
3968
3969 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3970 {
3971 Z_message("Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3972 return; //non power of two error
3973 }
3974
3975 int32_t tex_width = w*16;
3976 int32_t tex_height = h*16;
3977
3978 bool mustDestroyBmp = false;
3979 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3980
3981 if(!tex)
3982 {
3983 mustDestroyBmp = true;
3984 tex = create_bitmap_ex(8, tex_width, tex_height);
3985 clear_bitmap(tex);
3986 }
3987
3988 if(tile > 0) // TILE
3989 {
3990 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3991 }
3992 else // COMBO
3993 {
3994 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
3995 const int32_t tiletodraw = combo_tile(c, 0, 0);
3996 flip = flip ^ c.flip;
3997
3998 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3999 }
4000
4001 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
4002 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
4003 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
4004
4005 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
4006
4007 if(mustDestroyBmp)
4008 destroy_bitmap(tex);
4009
4010 }
4011
4012 12 void bmp_do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4013 {
4014 //Z_scripterrlog("rect sdci[13] is: %d\n", sdci[13]);
4015 //sdci[1]=layer
4016 //sdci[2]=x
4017 //sdci[3]=y
4018 //sdci[4]=x2
4019 //sdci[5]=y2
4020 //sdci[6]=color
4021 //sdci[7]=scale factor
4022 //sdci[8]=rotation anchor x
4023 //sdci[9]=rotation anchor y
4024 //sdci[10]=rotation angle
4025 //sdci[11]=fill
4026 //sdci[12]=opacity
4027 //sdci[17] Bitmap Pointer
4028
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(sdci[7]==0) //scale
4029 {
4030 return;
4031 }
4032
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if ( sdci[17] <= 0 )
4033 {
4034 Z_scripterrlog("bitmap->Rectangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4035 return;
4036 }
4037 12 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4038
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if ( refbmp == NULL ) return;
4039
4040
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4041
4042 12 int32_t x1=sdci[2]/10000;
4043 12 int32_t y1=sdci[3]/10000;
4044 12 int32_t x2=sdci[4]/10000;
4045 12 int32_t y2=sdci[5]/10000;
4046
4047
4048
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(x1>x2)
4049 {
4050 zc_swap(x1,x2);
4051 }
4052
4053
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(y1>y2)
4054 {
4055 zc_swap(y1,y2);
4056 }
4057
4058
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(sdci[7] != 10000)
4059 {
4060 int32_t w=x2-x1+1;
4061 int32_t h=y2-y1+1;
4062 int32_t w2=(w*sdci[7])/10000;
4063 int32_t h2=(h*sdci[7])/10000;
4064 x1=x1-((w2-w)/2);
4065 x2=x2+((w2-w)/2);
4066 y1=y1-((h2-h)/2);
4067 y2=y2+((h2-h)/2);
4068 }
4069
4070 12 int32_t color=sdci[6]/10000;
4071
4072
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(sdci[12]/10000<=127) //translucent
4073 {
4074 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4075 }
4076
4077
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(sdci[10]==0) //no rotation
4078 {
4079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(sdci[11]) //filled
4080 {
4081 rectfill(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
4082 }
4083 else //outline
4084 {
4085 12 rect(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
4086 }
4087 12 }
4088 else //rotate
4089 {
4090 int32_t xy[16];
4091 int32_t rx=sdci[8]/10000;
4092 int32_t ry=sdci[9]/10000;
4093 fixed ra1=itofix(sdci[10]%10000)/10000;
4094 fixed ra2=itofix(sdci[10]/10000);
4095 fixed ra=ra1+ra2;
4096 ra = (ra/360)*256;
4097
4098 fixed fcosa = fixcos(ra);
4099 fixed fsina = fixsin(ra);
4100
4101 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
4102 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
4103 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
4104 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
4105 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
4106 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
4107 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
4108 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
4109 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
4110 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
4111 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
4112 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
4113 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
4114 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
4115 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
4116 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
4117
4118 if(sdci[11]) //filled
4119 {
4120 polygon(refbmp, 4, xy, color);
4121 }
4122 else //outline
4123 {
4124 line(refbmp, xy[0], xy[1], xy[10], xy[11], color);
4125 line(refbmp, xy[2], xy[3], xy[12], xy[13], color);
4126 line(refbmp, xy[4], xy[5], xy[14], xy[15], color);
4127 line(refbmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
4128 }
4129 }
4130
4131 12 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4132 12 }
4133
4134 void bmp_do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4135 {
4136 //sdci[1]=layer
4137 //sdci[2]=x
4138 //sdci[3]=y
4139 //sdci[4]=tile
4140 //sdci[5]=cset
4141 //sdci[6]=width
4142 //sdci[7]=height
4143 //sdci[8]=overlay
4144 //sdci[9]=opacity
4145
4146 if ( sdci[17] <= 0 )
4147 {
4148 Z_scripterrlog("bitmap->DrawFrame() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4149 return;
4150 }
4151 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4152 if ( refbmp == NULL ) return;
4153
4154 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4155
4156 int32_t x=sdci[2]/10000;
4157 int32_t y=sdci[3]/10000;
4158
4159 int32_t tile=sdci[4]/10000;
4160 int32_t cs=sdci[5]/10000;
4161 int32_t w=sdci[6]/10000;
4162 int32_t h=sdci[7]/10000;
4163 bool overlay=sdci[8];
4164 bool trans=(sdci[9]/10000<=127);
4165
4166 frame2x2(refbmp, &QMisc, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
4167 }
4168
4169
4170 void bmp_do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4171 {
4172 //sdci[1]=layer
4173 //sdci[2]=x
4174 //sdci[3]=y
4175 //sdci[4]=radius
4176 //sdci[5]=color
4177 //sdci[6]=scale factor
4178 //sdci[7]=rotation anchor x
4179 //sdci[8]=rotation anchor y
4180 //sdci[9]=rotation angle
4181 //sdci[10]=fill
4182 //sdci[11]=opacity
4183 //sdci[17] Bitmap Pointer
4184 if(sdci[6]==0) //scale
4185 {
4186 return;
4187 }
4188 if ( sdci[17] <= 0 )
4189 {
4190 Z_scripterrlog("bitmap->Circle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4191 return;
4192 }
4193 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4194 if ( refbmp == NULL ) return;
4195
4196 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4197
4198 int32_t x1=sdci[2]/10000;
4199 int32_t y1=sdci[3]/10000;
4200 qword r=sdci[4];
4201
4202 if(sdci[6] != 10000)
4203 {
4204 r*=sdci[6];
4205 r/=10000;
4206 }
4207
4208 r/=10000;
4209 int32_t color=sdci[5]/10000;
4210
4211 if(sdci[11]/10000<=127) //translucent
4212 {
4213 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4214 }
4215
4216 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
4217 {
4218 int32_t xy[2];
4219 int32_t rx=sdci[7]/10000;
4220 int32_t ry=sdci[8]/10000;
4221 fixed ra1=itofix(sdci[9]%10000)/10000;
4222 fixed ra2=itofix(sdci[9]/10000);
4223 fixed ra=ra1+ra2;
4224 ra = (ra/360)*256;
4225
4226 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4227 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4228 x1=xy[0];
4229 y1=xy[1];
4230 }
4231
4232 if(sdci[10]) //filled
4233 {
4234 circlefill(refbmp, x1+xoffset, y1+yoffset, r, color);
4235 }
4236 else //outline
4237 {
4238 circle(refbmp, x1+xoffset, y1+yoffset, r, color);
4239 }
4240
4241 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4242 }
4243
4244
4245 void bmp_do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4246 {
4247 //sdci[1]=layer
4248 //sdci[2]=x
4249 //sdci[3]=y
4250 //sdci[4]=radius
4251 //sdci[5]=start angle
4252 //sdci[6]=end angle
4253 //sdci[7]=color
4254 //sdci[8]=scale factor
4255 //sdci[9]=rotation anchor x
4256 //sdci[10]=rotation anchor y
4257 //sdci[11]=rotation angle
4258 //sdci[12]=closed
4259 //sdci[13]=fill
4260 //sdci[14]=opacity
4261 //sdci[17] Bitmap Pointer
4262
4263 if(sdci[8]==0) //scale
4264 {
4265 return;
4266 }
4267 if ( sdci[17] <= 0 )
4268 {
4269 Z_scripterrlog("bitmap->Arc() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4270 return;
4271 }
4272 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4273 if ( refbmp == NULL ) return;
4274
4275 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4276
4277 int32_t cx=sdci[2]/10000;
4278 int32_t cy=sdci[3]/10000;
4279 qword r=sdci[4];
4280
4281 if(sdci[8] != 10000)
4282 {
4283 r*=sdci[8];
4284 r/=10000;
4285 }
4286
4287 r/=10000;
4288
4289 int32_t color=sdci[7]/10000;
4290
4291 fixed ra1=itofix(sdci[11]%10000)/10000;
4292 fixed ra2=itofix(sdci[11]/10000);
4293 fixed ra=ra1+ra2;
4294 ra = (ra/360)*256;
4295
4296
4297 fixed a1=itofix(sdci[5]%10000)/10000;
4298 fixed a2=itofix(sdci[5]/10000);
4299 fixed sa=a1+a2;
4300 sa = (sa/360)*256;
4301
4302 a1=itofix(sdci[6]%10000)/10000;
4303 a2=itofix(sdci[6]/10000);
4304 fixed ea=a1+a2;
4305 ea = (ea/360)*256;
4306
4307 if(sdci[11]!=0) //rotation
4308 {
4309 int32_t rx=sdci[9]/10000;
4310 int32_t ry=sdci[10]/10000;
4311
4312 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
4313 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
4314 ea-=ra;
4315 sa-=ra;
4316 }
4317
4318 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
4319 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
4320
4321 if(sdci[12]) //closed
4322 {
4323 if(sdci[13]) //filled
4324 {
4325 clear_bitmap(prim_bmp);
4326 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4327 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4328 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4329 int fillx = zc_max(0,fx)+xoffset;
4330 int filly = zc_max(0,fy)+yoffset;
4331 zprint2("bitmap->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
4332 floodfill(prim_bmp, fillx, filly, color);
4333
4334 if(sdci[14]/10000<=127) //translucent
4335 {
4336 draw_trans_sprite(refbmp, prim_bmp, 0,0);
4337 }
4338 else
4339 {
4340 draw_sprite(refbmp, prim_bmp, 0,0);
4341 }
4342 }
4343 else
4344 {
4345 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4346 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4347 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4348 }
4349 }
4350 else
4351 {
4352 if(sdci[14]/10000<=127) //translucent
4353 {
4354 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4355 }
4356
4357 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4358 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4359 }
4360 }
4361
4362
4363 void bmp_do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4364 {
4365 //sdci[1]=layer
4366 //sdci[2]=x
4367 //sdci[3]=y
4368 //sdci[4]=radiusx
4369 //sdci[5]=radiusy
4370 //sdci[6]=color
4371 //sdci[7]=scale factor
4372 //sdci[8]=rotation anchor x
4373 //sdci[9]=rotation anchor y
4374 //sdci[10]=rotation angle
4375 //sdci[11]=fill
4376 //sdci[12]=opacity
4377 //sdci[17] Bitmap Pointer
4378
4379 if(sdci[7]==0) //scale
4380 {
4381 return;
4382 }
4383 if ( sdci[17] <= 0 )
4384 {
4385 Z_scripterrlog("bitmap->Ellipse() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4386 return;
4387 }
4388 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4389 if ( refbmp == NULL ) return;
4390
4391 int32_t x1=sdci[2]/10000;
4392 int32_t y1=sdci[3]/10000;
4393 int32_t radx=sdci[4]/10000;
4394 radx*=sdci[7]/10000;
4395 int32_t rady=sdci[5]/10000;
4396 rady*=sdci[7]/10000;
4397 int32_t color=sdci[6]/10000;
4398 float rotation = sdci[10]/10000;
4399
4400 int32_t rx=sdci[8]/10000;
4401 int32_t ry=sdci[9]/10000;
4402 fixed ra1=itofix(sdci[10]%10000)/10000;
4403 fixed ra2=itofix(sdci[10]/10000);
4404 fixed ra=ra1+ra2;
4405 ra = (ra/360)*256;
4406
4407 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4408
4409 int32_t xy[2];
4410 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4411 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4412 x1=xy[0];
4413 y1=xy[1];
4414
4415 if(radx<1||rady<1||radx>255||rady>255) return;
4416
4417 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
4418
4419 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4420
4421 if(sdci[11]) //filled
4422 {
4423
4424 if(sdci[12]/10000<128) //translucent
4425 {
4426 clear_bitmap(prim_bmp);
4427 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4428 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4429 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4430 }
4431 else // no opacity
4432 {
4433 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4434 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4435 }
4436 }
4437 else //not filled
4438 {
4439 if(sdci[12]/10000<128) //translucent
4440 {
4441 clear_bitmap(prim_bmp);
4442 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4443 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4444 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4445 }
4446 else // no opacity
4447 {
4448 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4449 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4450 }
4451 }
4452
4453 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
4454 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
4455 // the ellipse, but it shouldn't be used anyway.
4456 if(color==0)
4457 {
4458 // This is very slow, so check the smallest possible square
4459 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
4460 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
4461
4462 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
4463 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
4464 if(getpixel(refbmp, x, y)==255)
4465 putpixel(refbmp, x, y, 0);
4466 }
4467
4468 script_drawing_commands.ReleaseSubBitmap(bitty);
4469 }
4470
4471
4472 void bmp_do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4473 {
4474 //sdci[1]=layer
4475 //sdci[2]=x
4476 //sdci[3]=y
4477 //sdci[4]=x2
4478 //sdci[5]=y2
4479 //sdci[6]=color
4480 //sdci[7]=scale factor
4481 //sdci[8]=rotation anchor x
4482 //sdci[9]=rotation anchor y
4483 //sdci[10]=rotation angle
4484 //sdci[11]=opacity
4485 //sdci[17] Bitmap Pointer
4486 if(sdci[7]==0) //scale
4487 {
4488 return;
4489 }
4490
4491 if ( sdci[17] <= 0 )
4492 {
4493 Z_scripterrlog("bitmap->Line() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4494 return;
4495 }
4496
4497 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4498 if ( refbmp == NULL ) return;
4499
4500 int32_t x1=sdci[2]/10000;
4501 int32_t y1=sdci[3]/10000;
4502 int32_t x2=sdci[4]/10000;
4503 int32_t y2=sdci[5]/10000;
4504
4505 if(sdci[7] != 10000)
4506 {
4507 int32_t w=x2-x1+1;
4508 int32_t h=y2-y1+1;
4509 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
4510 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
4511 x1=x1-((w2-w)/2);
4512 x2=x2+((w2-w)/2);
4513 y1=y1-((h2-h)/2);
4514 y2=y2+((h2-h)/2);
4515 }
4516
4517 int32_t color=sdci[6]/10000;
4518
4519 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4520
4521 if(sdci[11]/10000<=127) //translucent
4522 {
4523 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4524 }
4525
4526 if(sdci[10]!=0) //rotation
4527 {
4528 int32_t xy[4];
4529 int32_t rx=sdci[8]/10000;
4530 int32_t ry=sdci[9]/10000;
4531 fixed ra1=itofix(sdci[10]%10000)/10000;
4532 fixed ra2=itofix(sdci[10]/10000);
4533 fixed ra=ra1+ra2;
4534
4535 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4536 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4537 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
4538 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
4539 x1=xy[0];
4540 y1=xy[1];
4541 x2=xy[2];
4542 y2=xy[3];
4543 }
4544
4545 line(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
4546 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4547 }
4548
4549
4550 void bmp_do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4551 {
4552 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
4553 //sdci[17] Bitmap Pointer
4554
4555 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
4556 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
4557 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
4558 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
4559 };
4560
4561 if(sdci[11]/10000 < 128) //translucent
4562 {
4563 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4564 }
4565
4566 if ( sdci[17] <= 0 )
4567 {
4568 Z_scripterrlog("bitmap->Spline() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4569 return;
4570 }
4571
4572 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4573 if ( refbmp == NULL ) return;
4574
4575 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4576
4577 spline(refbmp, points, sdci[10]/10000);
4578
4579 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4580 }
4581
4582
4583 void bmp_do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4584 {
4585 //sdci[1]=layer
4586 //sdci[2]=x
4587 //sdci[3]=y
4588 //sdci[4]=color
4589 //sdci[5]=rotation anchor x
4590 //sdci[6]=rotation anchor y
4591 //sdci[7]=rotation angle
4592 //sdci[8]=opacity
4593 //sdci[17] Bitmap Pointer
4594 int32_t x1=sdci[2]/10000;
4595 int32_t y1=sdci[3]/10000;
4596 int32_t color=sdci[4]/10000;
4597
4598 if(sdci[8]/10000<=127) //translucent
4599 {
4600 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4601 }
4602
4603 if ( sdci[17] <= 0 )
4604 {
4605 Z_scripterrlog("bitmap->PutPixel() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4606 return;
4607 }
4608
4609 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4610 if ( refbmp == NULL ) return;
4611
4612 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4613
4614 if(sdci[7]!=0) //rotation
4615 {
4616 int32_t xy[2];
4617 int32_t rx=sdci[5]/10000;
4618 int32_t ry=sdci[6]/10000;
4619 fixed ra1=itofix(sdci[7]%10000)/10000;
4620 fixed ra2=itofix(sdci[7]/10000);
4621 fixed ra=ra1+ra2;
4622
4623 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4624 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4625 x1=xy[0];
4626 y1=xy[1];
4627 }
4628
4629 putpixel(refbmp, x1+xoffset, y1+yoffset, color);
4630 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4631 }
4632
4633
4634 264 void bmp_do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4635 {
4636 //sdci[1]=layer
4637 //sdci[2]=x
4638 //sdci[3]=y
4639 //sdci[4]=tile
4640 //sdci[5]=tile width
4641 //sdci[6]=tile height
4642 //sdci[7]=color (cset)
4643 //sdci[8]=scale x
4644 //sdci[9]=scale y
4645 //sdci[10]=rotation anchor x
4646 //sdci[11]=rotation anchor y
4647 //sdci[12]=rotation angle
4648 //sdci[13]=flip
4649 //sdci[14]=transparency
4650 //sdci[15]=opacity
4651 //sdci[17] Bitmap Pointer
4652
4653 264 int32_t w = sdci[5]/10000;
4654 264 int32_t h = sdci[6]/10000;
4655
4656
4/8
✓ Branch 0 taken 264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 264 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 264 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 264 times.
264 if(w < 1 || h < 1 || h > 20 || w > 20)
4657 {
4658 return;
4659 }
4660
4661
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
264 if ( sdci[17] <= 0 )
4662 {
4663 Z_scripterrlog("bitmap->DrawTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4664 return;
4665 }
4666
4667 264 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4668
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
264 if ( refbmp == NULL ) return;
4669
4670 264 int32_t xscale=sdci[8]/10000;
4671 264 int32_t yscale=sdci[9]/10000;
4672 264 int32_t rx = sdci[10]/10000;
4673 264 int32_t ry = sdci[11]/10000;
4674 264 float rotation=sdci[12]/10000;
4675 264 int32_t flip=(sdci[13]/10000)&3;
4676 264 bool transparency=sdci[14]!=0;
4677 264 int32_t opacity=sdci[15]/10000;
4678 264 int32_t color=sdci[7]/10000;
4679
4680 264 int32_t x1=sdci[2]/10000;
4681 264 int32_t y1=sdci[3]/10000;
4682
4683
4684 //don't scale if it's not safe to do so
4685 264 bool canscale = true;
4686
4687
2/4
✓ Branch 0 taken 264 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 264 times.
264 if(xscale==0||yscale==0)
4688 {
4689 return;
4690 }
4691
4692
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
264 if(xscale<0||yscale<0)
4693 264 canscale = false; //default size
4694
4695
2/4
✓ Branch 0 taken 264 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 264 times.
264 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4696
4697
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 264 times.
264 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4698 {
4699 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
4700
4701 if(transparency) //transparency
4702 {
4703 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4704 }
4705 else //no transparency
4706 {
4707 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4708 }
4709
4710 if(rotation != 0)
4711 {
4712 //low negative values indicate no anchor-point rotation
4713 if(rx>-777||ry>-777)
4714 {
4715 int32_t xy[2];
4716 fixed ra1=itofix(sdci[12]%10000)/10000;
4717 fixed ra2=itofix(sdci[12]/10000);
4718 fixed ra=ra1+ra2;
4719 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4720 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4721 x1=xy[0];
4722 y1=xy[1];
4723 }
4724
4725 if(canscale) //scale first
4726 {
4727 //damnit all, .. fixme.
4728 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4729 clear_bitmap(tempbit);
4730
4731 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4732
4733 if(opacity < 128)
4734 {
4735 clear_bitmap(prim_bmp);
4736 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4737 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
4738 }
4739 else
4740 {
4741 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4742 }
4743
4744 destroy_bitmap(tempbit);
4745 }
4746 else //no scale
4747 {
4748 if(opacity < 128)
4749 {
4750 clear_bitmap(prim_bmp);
4751 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4752 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4753 }
4754 else
4755 {
4756 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4757 }
4758 }
4759 }
4760 else //scale only
4761 {
4762 if(canscale)
4763 {
4764 if(opacity<128)
4765 {
4766 clear_bitmap(prim_bmp);
4767 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4768 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4769 }
4770 else
4771 {
4772 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4773 }
4774 }
4775 else //error -do not scale
4776 {
4777 if(opacity<128)
4778 {
4779 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4780 }
4781 else
4782 {
4783 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4784 }
4785 }
4786 }
4787
4788 script_drawing_commands.ReleaseSubBitmap(pbitty);
4789
4790 }
4791 else // no scale or rotation
4792 {
4793
1/2
✓ Branch 0 taken 264 times.
✗ Branch 1 not taken.
264 if(transparency)
4794 {
4795
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
264 if(opacity<=127)
4796 TileHelper::OverTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4797 else
4798 264 TileHelper::OverTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4799 264 }
4800 else
4801 {
4802 if(opacity<=127)
4803 TileHelper::PutTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4804 else
4805 TileHelper::OldPutTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4806 }
4807 }
4808 264 }
4809
4810 void bmp_do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4811 {
4812 //sdci[1]=layer
4813 //sdci[2]=x
4814 //sdci[3]=y
4815 //sdci[4]=tile
4816 //sdci[5]=tile width
4817 //sdci[6]=tile height
4818 //sdci[7]=flip
4819 //sdci[17] Bitmap Pointer
4820
4821 int32_t w = sdci[5]/10000;
4822 int32_t h = sdci[6]/10000;
4823
4824 if(w < 1 || h < 1 || h > 20 || w > 20)
4825 {
4826 return;
4827 }
4828
4829 if ( sdci[17] <= 0 )
4830 {
4831 Z_scripterrlog("bitmap->DrawTileCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4832 return;
4833 }
4834
4835 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4836 if ( refbmp == NULL ) return;
4837
4838 int32_t flip=(sdci[7]/10000)&3;
4839
4840 int32_t x1=sdci[2]/10000;
4841 int32_t y1=sdci[3]/10000;
4842
4843 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4844
4845 TileHelper::OverTileCloaked(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
4846 }
4847
4848
4849 3 void bmp_do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4850 {
4851 //sdci[1]=layer
4852 //sdci[2]=x
4853 //sdci[3]=y
4854 //sdci[4]=combo
4855 //sdci[5]=tile width
4856 //sdci[6]=tile height
4857 //sdci[7]=color (cset)
4858 //sdci[8]=scale x
4859 //sdci[9]=scale y
4860 //sdci[10]=rotation anchor x
4861 //sdci[11]=rotation anchor y
4862 //sdci[12]=rotation angle
4863 //sdci[13]=frame
4864 //sdci[14]=flip
4865 //sdci[15]=transparency
4866 //sdci[16]=opacity
4867 //sdci[17] Bitmap Pointer
4868 3 int32_t w = sdci[5]/10000;
4869 3 int32_t h = sdci[6]/10000;
4870
4871
4/8
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
3 if(w<1||h<1||h>20||w>20)
4872 {
4873 return;
4874 }
4875
4876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( sdci[17] <= 0 )
4877 {
4878 Z_scripterrlog("bitmap->DrawCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4879 return;
4880 }
4881
4882 3 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4883
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if ( refbmp == NULL ) return;
4884 3 int32_t cmb = (sdci[4]/10000);
4885
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if((unsigned)cmb >= MAXCOMBOS)
4886 {
4887 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4888 return;
4889 }
4890
4891 3 int32_t xscale=sdci[8]/10000;
4892 3 int32_t yscale=sdci[9]/10000;
4893 3 int32_t rx = sdci[10]/10000; //these work now
4894 3 int32_t ry = sdci[11]/10000; //these work now
4895 3 float rotation=sdci[12]/10000;
4896
4897 3 bool transparency=sdci[15]!=0;
4898 3 int32_t opacity=sdci[16]/10000;
4899 3 int32_t color=sdci[7]/10000;
4900 3 int32_t x1=sdci[2]/10000;
4901 3 int32_t y1=sdci[3]/10000;
4902
4903 3 const newcombo & c = combobuf[cmb];
4904 3 int32_t tiletodraw = combo_tile(c, x1, y1);
4905 3 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
4906 3 int32_t skiprows=c.skipanimy;
4907
4908
4909 //don't scale if it's not safe to do so
4910 3 bool canscale = true;
4911
4912
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if(xscale==0||yscale==0)
4913 {
4914 return;
4915 }
4916
4917
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(xscale<0||yscale<0)
4918 3 canscale = false; //default size
4919
4920
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4921
4922
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4923 {
4924 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
4925
4926 if(transparency)
4927 {
4928 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4929 }
4930 else //no transparency
4931 {
4932 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4933 }
4934
4935 if(rotation != 0) // rotate
4936 {
4937 //fixed point sucks ;0
4938 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
4939 {
4940 int32_t xy[2];
4941 fixed ra1=itofix(sdci[12]%10000)/10000;
4942 fixed ra2=itofix(sdci[12]/10000);
4943 fixed ra=ra1+ra2;
4944 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4945 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4946 x1=xy[0];
4947 y1=xy[1];
4948 }
4949
4950 if(canscale) //scale first
4951 {
4952 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4953 clear_bitmap(tempbit);
4954
4955 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4956
4957 if(opacity < 128)
4958 {
4959 clear_bitmap(prim_bmp);
4960 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4961 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4962 }
4963 else
4964 {
4965 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4966 }
4967
4968 destroy_bitmap(tempbit);
4969 }
4970 else //no scale
4971 {
4972 if(opacity < 128)
4973 {
4974 clear_bitmap(prim_bmp);
4975 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4976 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4977 }
4978 else
4979 {
4980 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4981 }
4982 }
4983 }
4984 else //scale only
4985 {
4986 if(canscale)
4987 {
4988 if(opacity<128)
4989 {
4990 clear_bitmap(prim_bmp);
4991 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4992 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4993 }
4994 else
4995 {
4996 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4997 }
4998 }
4999 else //error -do not scale
5000 {
5001 if(opacity<128)
5002 {
5003 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
5004 }
5005 else
5006 {
5007 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
5008 }
5009 }
5010 }
5011
5012 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
5013 }
5014 else // no scale or rotation
5015 {
5016
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(transparency)
5017 {
5018
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(opacity<=127)
5019 TileHelper::OverTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
5020 else
5021 3 TileHelper::OverTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
5022 3 }
5023 else
5024 {
5025 if(opacity<=127)
5026 TileHelper::PutTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
5027 else
5028 TileHelper::OldPutTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
5029 }
5030 }
5031 3 }
5032
5033
5034 void bmp_do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5035 {
5036 //sdci[1]=layer
5037 //sdci[2]=x
5038 //sdci[3]=y
5039 //sdci[4]=combo
5040 //sdci[5]=tile width
5041 //sdci[6]=tile height
5042 //sdci[7]=flip
5043 //sdci[17] Bitmap Pointer
5044
5045 int32_t w = sdci[5]/10000;
5046 int32_t h = sdci[6]/10000;
5047
5048 if(w<1||h<1||h>20||w>20)
5049 {
5050 return;
5051 }
5052
5053 if ( sdci[17] <= 0 )
5054 {
5055 Z_scripterrlog("bitmap->DrawComboCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5056 return;
5057 }
5058
5059 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5060 if ( refbmp == NULL ) return;
5061 int32_t cmb = (sdci[4]/10000);
5062 if((unsigned)cmb >= MAXCOMBOS)
5063 {
5064 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
5065 return;
5066 }
5067
5068 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5069
5070 int32_t x1=sdci[2]/10000;
5071 int32_t y1=sdci[3]/10000;
5072
5073 const newcombo & c = combobuf[cmb];
5074 int32_t tiletodraw = combo_tile(c, x1, y1);
5075 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
5076 int32_t skiprows=c.skipanimy;
5077
5078 TileHelper::OverTileCloaked(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
5079 }
5080
5081
5082 4630 void bmp_do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5083 {
5084 /* layer, x, y, tile, color opacity */
5085 //sdci[17] Bitmap Pointer
5086
5087 4630 int32_t opacity = sdci[6]/10000;
5088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4630 times.
4630 if ( sdci[17] <= 0 )
5089 {
5090 Z_scripterrlog("bitmap->FastTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5091 return;
5092 }
5093 4630 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5094
1/2
✓ Branch 0 taken 4630 times.
✗ Branch 1 not taken.
4630 if ( refbmp == NULL ) return;
5095
5096
2/4
✓ Branch 0 taken 4630 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4630 times.
✗ Branch 3 not taken.
4630 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5097
5098
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4630 times.
4630 if(opacity < 128)
5099 overtiletranslucent16(refbmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0, opacity);
5100 else
5101 4630 overtile16(refbmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0);
5102 4630 }
5103
5104 void do_bmpwritetile(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5105 {
5106 /* layer, x, y, tile, is8bit, mask */
5107 //sdci[17] Bitmap Pointer
5108 if ( sdci[17] <= 0 )
5109 {
5110 Z_scripterrlog("bitmap->WriteTile() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5111 return;
5112 }
5113 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5114 if ( refbmp == NULL ) return;
5115
5116 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5117
5118 int32_t x = (sdci[2]/10000), y = (sdci[3]/10000), tl = (sdci[4]/10000);
5119 bool is8bit = sdci[5]!=0, mask = sdci[6]!=0;
5120
5121 write_tile(newtilebuf, refbmp, tl, x+xoffset, y+yoffset, is8bit, mask);
5122 }
5123
5124 void do_bmpdither(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5125 {
5126 /* layer, mask, color, ditherType, ditherArg */
5127 //sdci[2] Mask Bitmap Pointer
5128 //sdci[3] Color
5129 //sdci[17] Bitmap Pointer
5130 if ( sdci[17] <= 0 )
5131 {
5132 Z_scripterrlog("bitmap->Dither() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5133 return;
5134 }
5135 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5136 if ( refbmp == NULL ) return;
5137 if ( sdci[2] <= 0 )
5138 {
5139 Z_scripterrlog("bitmap->Dither() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5140 return;
5141 }
5142 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]-10);
5143 if ( mask == NULL ) return;
5144
5145 int32_t dType = sdci[4] / 10000L;
5146 if(dType < 0 || dType >= dithMax)
5147 {
5148 Z_scripterrlog("bitmap->Dither() used an invalid dither type: %d. Aborting.\n", dType);
5149 return;
5150 }
5151
5152 ditherblit(refbmp, mask, byte(sdci[3]/10000L), dType, sdci[5]/10000L);
5153 }
5154
5155 void do_bmpreplcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5156 {
5157 /* layer, shift, startcol, endcol */
5158 //sdci[2] NewCol
5159 //sdci[3] StartCol
5160 //sdci[4] EndCol
5161 //sdci[17] Bitmap Pointer
5162 if ( sdci[17] <= 0 )
5163 {
5164 Z_scripterrlog("bitmap->ReplaceColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5165 return;
5166 }
5167 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5168 if ( refbmp == NULL ) return;
5169 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, false);
5170 }
5171
5172 void do_bmpshiftcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5173 {
5174 /* layer, shift, startcol, endcol */
5175 //sdci[2] ShiftAmount
5176 //sdci[3] StartCol
5177 //sdci[4] EndCol
5178 //sdci[17] Bitmap Pointer
5179 if ( sdci[17] <= 0 )
5180 {
5181 Z_scripterrlog("bitmap->ShiftColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5182 return;
5183 }
5184 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5185 if ( refbmp == NULL ) return;
5186 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, true);
5187 }
5188
5189 void do_bmpmaskdraw(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5190 {
5191 /* layer, mask, color */
5192 //sdci[2] Mask Bitmap Pointer
5193 //sdci[3] Color
5194 //sdci[4] start mask color
5195 //sdci[5] end mask color
5196 //sdci[17] Bitmap Pointer
5197 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5198 if ( refbmp == NULL )
5199 {
5200 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5201 return;
5202 }
5203 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]-10);
5204 if ( mask == NULL )
5205 {
5206 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5207 return;
5208 }
5209 auto fillcol = sdci[3]/10000L;
5210 if(unsigned(fillcol) > 0xFF) return; //invalid color, nothing to draw
5211 auto startcol = vbound(sdci[4]/10000L,0x00,0xFF);
5212 auto endcol = vbound(sdci[5]/10000L,0x00,0xFF);
5213 mask_colorfill(refbmp, mask, fillcol, startcol, endcol);
5214 }
5215
5216 void do_bmpmaskblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5217 {
5218 /* layer, mask, color */
5219 //sdci[2] Mask Bitmap Pointer
5220 //sdci[3] Pattern Bitmap
5221 //sdci[4] bool 'pattern repeats'
5222 //sdci[5] start mask color
5223 //sdci[6] end mask color
5224 //sdci[17] Bitmap Pointer
5225 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5226 if ( refbmp == NULL )
5227 {
5228 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5229 return;
5230 }
5231 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]-10);
5232 if ( mask == NULL )
5233 {
5234 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (mask) id: %d. Aborting.\n", sdci[2]);
5235 return;
5236 }
5237 BITMAP *pattern = FFCore.GetScriptBitmap(sdci[3]-10);
5238 if ( pattern == NULL )
5239 {
5240 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (pattern) id: %d. Aborting.\n", sdci[3]);
5241 return;
5242 }
5243 bool repeats = sdci[4]!=0;
5244 auto startcol = vbound(sdci[5]/10000L,0x00,0xFF);
5245 auto endcol = vbound(sdci[6]/10000L,0x00,0xFF);
5246 mask_blit(refbmp, mask, pattern, repeats, startcol, endcol);
5247 }
5248
5249 void bmp_do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5250 {
5251 /* layer, x, y, tile, color opacity */
5252 //sdci[17] Bitmap Pointer
5253 int32_t opacity = sdci[6] / 10000;
5254 int32_t x1 = sdci[2] / 10000;
5255 int32_t y1 = sdci[3] / 10000;
5256 int32_t index = sdci[4]/10000;
5257 if ( sdci[17] <= 0 )
5258 {
5259 Z_scripterrlog("bitmap->FastCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5260 return;
5261 }
5262 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5263 if ( refbmp == NULL ) return;
5264 int32_t cmb = (sdci[4]/10000);
5265 if((unsigned)cmb >= MAXCOMBOS)
5266 {
5267 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
5268 return;
5269 }
5270
5271 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5272
5273 //if( index >= MAXCOMBOS ) return; //bleh.
5274 /*
5275 const newcombo & c = combobuf[index];
5276
5277 if(opacity < 128)
5278 overtiletranslucent16(refbmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip, opacity);
5279 else
5280 overtile16(refbmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip);
5281 */
5282
5283 if(opacity < 128)
5284 {
5285 //void overcomboblocktranslucent(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h, int32_t opacity)
5286 overcomboblocktranslucent(refbmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1, 128);
5287
5288 }
5289 else
5290 {
5291 //overcomboblock(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h)
5292 overcomboblock(refbmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1);
5293 }
5294 }
5295
5296
5297
5298 void bmp_do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5299 {
5300 //sdci[17] Bitmap Pointer
5301 if ( sdci[17] <= 0 )
5302 {
5303 Z_scripterrlog("bitmap->DrawCharacter() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5304 return;
5305 }
5306 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5307 if ( refbmp == NULL ) return;
5308
5309 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5310
5311 //broken 2.50.2 and earlier drawcharacter()
5312 if ( get_bit(quest_rules, qr_BROKENCHARINTDRAWING) )
5313 {
5314 //sdci[1]=layer
5315 //sdci[2]=x
5316 //sdci[3]=y
5317 //sdci[4]=font
5318 //sdci[5]=color
5319 //sdci[6]=bg color
5320 //sdci[7]=strech x (width)
5321 //sdci[8]=stretch y (height)
5322 //sdci[9]=char
5323 //sdci[10]=opacity
5324 //sdci[17] Bitmap Pointer
5325
5326 int32_t x=sdci[2]/10000;
5327 int32_t y=sdci[3]/10000;
5328 int32_t font_index=sdci[4]/10000;
5329 int32_t color=sdci[5]/10000;
5330 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5331 int32_t w=sdci[7]/10000;
5332 int32_t h=sdci[8]/10000;
5333 char glyph=char(sdci[9]/10000);
5334 int32_t opacity=sdci[10]/10000;
5335
5336 //safe check
5337 if(bg_color < -1) bg_color = -1;
5338
5339 if(w>512) w=512; //w=vbound(w,0,512);
5340
5341 if(h>512) h=512; //h=vbound(h,0,512);
5342
5343 //undone
5344 if(w>0&&h>0)//stretch the character
5345 {
5346 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5347
5348 if(opacity < 128)
5349 {
5350 if(w>128||h>128)
5351 {
5352 clear_bitmap(prim_bmp);
5353
5354 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5355 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5356 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5357 }
5358 else //this is faster
5359 {
5360 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5361
5362 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5363 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5364 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5365
5366 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5367 }
5368 }
5369 else // no opacity
5370 {
5371 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5372 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5373 }
5374
5375 }
5376 else //no stretch
5377 {
5378 if(opacity < 128)
5379 {
5380 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5381 clear_bitmap(pbmp);
5382
5383 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5384 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5385
5386 destroy_bitmap(pbmp);
5387 }
5388 else // no opacity
5389 {
5390 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5391 }
5392 }
5393 }
5394
5395 else //2.53.0 fixed version and later.
5396 {
5397
5398 //sdci[1]=layer
5399 //sdci[2]=x
5400 //sdci[3]=y
5401 //sdci[4]=font
5402 //sdci[5]=color
5403 //sdci[6]=bg color
5404 //sdci[7]=strech x (width)
5405 //sdci[8]=stretch y (height)
5406 //sdci[9]=char
5407 //sdci[10]=opacity
5408
5409 int32_t x=sdci[2]/10000;
5410 int32_t y=sdci[3]/10000;
5411 int32_t font_index=sdci[4]/10000;
5412 int32_t color=sdci[5]/10000;
5413 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5414 int32_t w=sdci[7]/10000;
5415 int32_t h=sdci[8]/10000;
5416 char glyph=char(sdci[9]/10000);
5417 int32_t opacity=sdci[10]/10000;
5418
5419 //safe check
5420 if(bg_color < -1) bg_color = -1;
5421
5422 if(w>512) w=512; //w=vbound(w,0,512);
5423
5424 if(h>512) h=512; //h=vbound(h,0,512);
5425
5426 //undone
5427 if(w>0&&h>0)//stretch the character
5428 {
5429 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5430
5431 if(opacity < 128)
5432 {
5433 if(w>128||h>128)
5434 {
5435 clear_bitmap(prim_bmp);
5436
5437 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5438 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5439 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5440 }
5441 else //this is faster
5442 {
5443 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5444
5445 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5446 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5447 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5448
5449 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5450 }
5451 }
5452 else // no opacity
5453 {
5454 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5455 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5456 }
5457
5458 }
5459 else //no stretch
5460 {
5461 if(opacity < 128)
5462 {
5463 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5464 clear_bitmap(pbmp);
5465
5466 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5467 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5468
5469 destroy_bitmap(pbmp);
5470 }
5471 else // no opacity
5472 {
5473 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5474 }
5475 }
5476
5477 }
5478
5479 }
5480
5481
5482 void bmp_do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5483 {
5484 if ( sdci[17] <= 0 )
5485 {
5486 Z_scripterrlog("bitmap->DrawInteger() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5487 return;
5488 }
5489 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5490 if ( refbmp == NULL ) return;
5491
5492 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5493
5494 //broken 2.50.2 and earlier drawinteger()
5495 if ( get_bit(quest_rules, qr_BROKENCHARINTDRAWING) )
5496 {
5497 //sdci[1]=layer
5498 //sdci[2]=x
5499 //sdci[3]=y
5500 //sdci[4]=font
5501 //sdci[5]=color
5502 //sdci[6]=bg color
5503 //sdci[7]=strech x (width)
5504 //sdci[8]=stretch y (height)
5505 //sdci[9]=integer
5506 //sdci[10]=num decimal places
5507 //sdci[11]=opacity
5508 //sdci[17] Bitmap Pointer
5509
5510 int32_t x=sdci[2]/10000;
5511 int32_t y=sdci[3]/10000;
5512 int32_t font_index=sdci[4]/10000;
5513 int32_t color=sdci[5]/10000;
5514 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5515 int32_t w=sdci[7]/10000;
5516 int32_t h=sdci[8]/10000;
5517 //float number=static_cast<float>(sdci[9])/10000.0f;
5518 int32_t decplace=sdci[10]/10000;
5519 int32_t opacity=sdci[11]/10000;
5520
5521 //safe check
5522 if(bg_color < -1) bg_color = -1;
5523
5524 if(w>512) w=512; //w=vbound(w,0,512);
5525
5526 if(h>512) h=512; //h=vbound(h,0,512);
5527
5528 char numbuf[15];
5529
5530 switch(decplace)
5531 {
5532 default:
5533 case 0:
5534 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5535 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5536
5537 case 1:
5538 //sprintf(numbuf,"%.01f",number);
5539 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5540 break;
5541
5542 case 2:
5543 //sprintf(numbuf,"%.02f",number);
5544 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5545 break;
5546
5547 case 3:
5548 //sprintf(numbuf,"%.03f",number);
5549 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5550 break;
5551
5552 case 4:
5553 //sprintf(numbuf,"%.04f",number);
5554 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5555 break;
5556 }
5557
5558 if(w>0&&h>0)//stretch
5559 {
5560 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5561
5562 if(opacity < 128)
5563 {
5564 if(w>128||h>128)
5565 {
5566 clear_bitmap(prim_bmp);
5567
5568 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5569 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5570 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5571 }
5572 else
5573 {
5574 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5575 clear_bitmap(pbmp2);
5576
5577 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5578 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5579 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5580
5581 destroy_bitmap(pbmp2);
5582 }
5583 }
5584 else // no opacity
5585 {
5586 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5587 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5588 }
5589
5590 }
5591 else //no stretch
5592 {
5593 if(opacity < 128)
5594 {
5595 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5596 clear_bitmap(pbmp);
5597
5598 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5599 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5600
5601 destroy_bitmap(pbmp);
5602 }
5603 else // no opacity
5604 {
5605 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5606 }
5607 }
5608
5609 }
5610
5611 else //2.53.0 fixed version and later.
5612 {
5613 //sdci[1]=layer
5614 //sdci[2]=x
5615 //sdci[3]=y
5616 //sdci[4]=font
5617 //sdci[5]=color
5618 //sdci[6]=bg color
5619 //sdci[7]=strech x (width)
5620 //sdci[8]=stretch y (height)
5621 //sdci[9]=integer
5622 //sdci[10]=num decimal places
5623 //sdci[11]=opacity
5624
5625 int32_t x=sdci[2]/10000;
5626 int32_t y=sdci[3]/10000;
5627 int32_t font_index=sdci[4]/10000;
5628 int32_t color=sdci[5]/10000;
5629 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5630 int32_t w=sdci[7]/10000;
5631 int32_t h=sdci[8]/10000;
5632 //float number=static_cast<float>(sdci[9])/10000.0f;
5633 //int32_t numberint = sdci[9]/10000;
5634 int32_t decplace=sdci[10]/10000;
5635 int32_t opacity=sdci[11]/10000;
5636
5637 //safe check
5638 if(bg_color < -1) bg_color = -1;
5639
5640 if(w>512) w=512; //w=vbound(w,0,512);
5641
5642 if(h>512) h=512; //h=vbound(h,0,512);
5643
5644 char numbuf[15];
5645
5646 switch(decplace)
5647 {
5648 default:
5649 case 0:
5650 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5651 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5652
5653 case 1:
5654 //sprintf(numbuf,"%.01f",number);
5655 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5656 break;
5657
5658 case 2:
5659 //sprintf(numbuf,"%.02f",number);
5660 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5661 break;
5662
5663 case 3:
5664 //sprintf(numbuf,"%.03f",number);
5665 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5666 break;
5667
5668 case 4:
5669 //sprintf(numbuf,"%.04f",number);
5670 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5671 break;
5672 }
5673
5674 //FONT* font=get_zc_font(sdci[4]/10000);
5675
5676 if(w>0&&h>0)//stretch
5677 {
5678 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
5679 clear_bitmap(pbmp);
5680 //script_drawing_commands.GetSmallTextureBitmap(1,1);
5681
5682 if(opacity < 128)
5683 {
5684 if(w>128||h>128)
5685 {
5686 clear_bitmap(prim_bmp);
5687
5688 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5689 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5690 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5691 }
5692 else
5693 {
5694 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5695 clear_bitmap(pbmp2);
5696
5697 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5698 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5699 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5700
5701 destroy_bitmap(pbmp2);
5702 }
5703 }
5704 else // no opacity
5705 {
5706 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5707 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5708 }
5709
5710 }
5711 else //no stretch
5712 {
5713 if(opacity < 128)
5714 {
5715 FONT* font = get_zc_font(font_index);
5716 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
5717 clear_bitmap(pbmp);
5718
5719 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
5720 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5721
5722 destroy_bitmap(pbmp);
5723 }
5724 else // no opacity
5725 {
5726 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5727 }
5728 }
5729 }
5730 }
5731
5732
5733 void bmp_do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5734 {
5735 //sdci[1]=layer
5736 //sdci[2]=x
5737 //sdci[3]=y
5738 //sdci[4]=font
5739 //sdci[5]=color
5740 //sdci[6]=bg color
5741 //sdci[7]=format_option
5742 //sdci[8]=string
5743 //sdci[9]=opacity
5744 //sdci[17] Bitmap Pointer
5745 if ( sdci[17] <= 0 )
5746 {
5747 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5748 return;
5749 }
5750
5751 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5752 if ( refbmp == NULL ) return;
5753
5754 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5755
5756 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5757
5758 if(!str)
5759 {
5760 al_trace("String pointer is null! Internal error. \n");
5761 return;
5762 }
5763
5764 int32_t x=sdci[2]/10000;
5765 int32_t y=sdci[3]/10000;
5766 FONT* font=get_zc_font(sdci[4]/10000);
5767 int32_t color=sdci[5]/10000;
5768 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5769 int32_t format_type=sdci[7]/10000;
5770 int32_t opacity=sdci[9]/10000;
5771 //sdci[8] not needed :)
5772
5773 //safe check
5774 if(bg_color < -1) bg_color = -1;
5775
5776 if(opacity < 128)
5777 {
5778 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5779 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5780 clear_bitmap(pbmp);
5781 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
5782 if(format_type == 2) // right-sided text
5783 x-=width;
5784 else if(format_type == 1) // centered text
5785 x-=width/2;
5786 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5787 destroy_bitmap(pbmp);
5788 }
5789 else // no opacity
5790 {
5791 if(format_type == 2) // right-sided text
5792 {
5793 textout_right_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5794 }
5795 else if(format_type == 1) // centered text
5796 {
5797 textout_centre_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5798 }
5799 else // standard left-sided text
5800 {
5801 textout_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5802 }
5803 }
5804 }
5805
5806 void bmp_do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5807 {
5808 //sdci[1]=layer
5809 //sdci[2]=x
5810 //sdci[3]=y
5811 //sdci[4]=font
5812 //sdci[5]=color
5813 //sdci[6]=bg color
5814 //sdci[7]=format_option
5815 //sdci[8]=string
5816 //sdci[9]=opacity
5817 //sdci[10]=shadowtype
5818 //sdci[11]=shadow_color
5819 //sdci[17] Bitmap Pointer
5820 if ( sdci[17] <= 0 )
5821 {
5822 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5823 return;
5824 }
5825
5826 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5827 if ( refbmp == NULL ) return;
5828
5829 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5830
5831 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5832
5833 if(!str)
5834 {
5835 al_trace("String pointer is null! Internal error. \n");
5836 return;
5837 }
5838
5839 int32_t x=sdci[2]/10000;
5840 int32_t y=sdci[3]/10000;
5841 FONT* font=get_zc_font(sdci[4]/10000);
5842 int32_t color=sdci[5]/10000;
5843 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5844 int32_t format_type=sdci[7]/10000;
5845 int32_t opacity=sdci[9]/10000;
5846 int32_t textstyle = sdci[10]/10000;
5847 int32_t shadow_color = sdci[11]/10000;
5848 //sdci[8] not needed :)
5849
5850 //safe check
5851 if(bg_color < -1) bg_color = -1;
5852
5853 if(opacity < 128)
5854 {
5855 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5856 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5857 clear_bitmap(pbmp);
5858 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
5859 if(format_type == 2) // right-sided text
5860 x-=width;
5861 else if(format_type == 1) // centered text
5862 x-=width/2;
5863 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5864 destroy_bitmap(pbmp);
5865 }
5866 else // no opacity
5867 {
5868 textout_styled_aligned_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
5869 }
5870 }
5871
5872 7473 void bmp_do_clearr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5873 {
5874 //sdci[1]=layer
5875 //sdci[17] Bitmap Pointer
5876 //Z_scripterrlog("bitmap->Clear() pointer is: %d\n", sdci[17]);
5877
1/2
✓ Branch 0 taken 7473 times.
✗ Branch 1 not taken.
7473 if ( sdci[17] <= 0 )
5878 {
5879 Z_scripterrlog("bitmap->Clear() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5880 return;
5881 }
5882 7473 int32_t bitid = sdci[17] - 10;
5883
1/2
✓ Branch 0 taken 7473 times.
✗ Branch 1 not taken.
7473 if ( scb.script_created_bitmaps[bitid].u_bmp )
5884 7473 clear_bitmap(scb.script_created_bitmaps[bitid].u_bmp);
5885 7473 }
5886
5887 190 void bmp_do_clearcolorr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5888 {
5889 //sdci[1]=layer
5890 //sdci[2]=color
5891 //sdci[17] Bitmap Pointer
5892 190 int32_t pal_color = sdci[2]/10000;
5893
1/2
✓ Branch 0 taken 190 times.
✗ Branch 1 not taken.
190 if ( sdci[17] <= 0 )
5894 {
5895 Z_scripterrlog("bitmap->ClearToColor() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5896 return;
5897 }
5898 190 int32_t bitid = sdci[17] - 10;
5899
1/2
✓ Branch 0 taken 190 times.
✗ Branch 1 not taken.
190 if ( scb.script_created_bitmaps[bitid].u_bmp )
5900 190 clear_to_color(scb.script_created_bitmaps[bitid].u_bmp, pal_color);
5901 190 }
5902
5903
5904 8650 void bmp_do_regenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5905 {
5906 //sdci[1]=layer
5907 8650 int32_t h = sdci[3]/10000;
5908 8650 int32_t w = sdci[2]/10000;
5909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8650 times.
8650 if ( get_bit(quest_rules, qr_OLDCREATEBITMAP_ARGS) )
5910 {
5911 //flip height and width
5912 h = h ^ w;
5913 w = h ^ w;
5914 h = h ^ w;
5915 }
5916 //sdci[17] Bitmap Pointer
5917 //Z_scripterrlog("bitmap->Create() pointer is: %d\n", sdci[17]);
5918
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8650 times.
8650 if ( sdci[17] <= 0 )
5919 {
5920 Z_scripterrlog("bitmap->Create() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5921 return;
5922 }
5923 8650 int32_t bitid = sdci[17] - 10;
5924
2/2
✓ Branch 0 taken 8525 times.
✓ Branch 1 taken 125 times.
8650 if ( scb.script_created_bitmaps[bitid].u_bmp )
5925 8525 destroy_bitmap(scb.script_created_bitmaps[bitid].u_bmp);
5926 8650 scb.script_created_bitmaps[bitid].u_bmp = create_bitmap_ex(8,w,h);
5927
5928 8650 scb.script_created_bitmaps[bitid].width = w;
5929 8650 scb.script_created_bitmaps[bitid].height = h;
5930
5931
5932
5933 8650 }
5934
5935 void bmp_do_readr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5936 {
5937 //sdci[1]=layer
5938 //sdci[2]=filename
5939 //sdci[3]=y
5940 //sdci[4]=font
5941 //sdci[5]=color
5942 //sdci[6]=bg color
5943 //sdci[7]=format_option
5944 //sdci[8]=string
5945 //sdci[9]=opacity
5946 //sdci[17] Bitmap Pointer
5947 //Z_scripterrlog("bitmap->Read() pointer is: %d\n", sdci[17]);
5948 if ( sdci[17] <= 0 )
5949 {
5950 Z_scripterrlog("bitmap->Read() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5951 return;
5952 }
5953 int32_t bitid = sdci[17] - 10;
5954 scb.script_created_bitmaps[bitid].destroy();
5955
5956 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5957
5958 //char *cptr = new char[str->size()+1]; // +1 to account for \0 byte
5959 // std::strncpy(cptr, str->c_str(), str->size());
5960 // Z_scripterrlog("The following should be the filename string:\n");
5961 //Z_scripterrlog(" %s\n", cptr);
5962
5963 if(!str)
5964 {
5965 al_trace("String pointer is null! Internal error. \n");
5966 return;
5967 }
5968
5969 // Z_scripterrlog("Trying to read filename %s\n", cptr);
5970 PALETTE tempPal;
5971 get_palette(tempPal);
5972 if ( checkPath(str->c_str(), false) )
5973 {
5974 scb.script_created_bitmaps[bitid].u_bmp = load_bitmap(str->c_str(), tempPal);
5975 scb.script_created_bitmaps[bitid].width = scb.script_created_bitmaps[bitid].u_bmp->w;
5976 scb.script_created_bitmaps[bitid].height = scb.script_created_bitmaps[bitid].u_bmp->h;
5977 if ( !scb.script_created_bitmaps[bitid].u_bmp )
5978 {
5979 Z_scripterrlog("Failed to load image file %s.\nMaking a blank bitmap on the pointer.\n", str->c_str());
5980 //scb.script_created_bitmaps[bitid].u_bmp = create_bitmap_ex(8,256,176);
5981 //clear_bitmap(scb.script_created_bitmaps[bitid].u_bmp);
5982 }
5983 else
5984 {
5985 zprint("Read image file %s\n",str->c_str());
5986 }
5987 }
5988 else
5989 {
5990 Z_scripterrlog("Failed to load image file: %s. File not found. Creating a blank bitmap on the pointer.\n", str->c_str());
5991 scb.script_created_bitmaps[bitid].u_bmp = create_bitmap_ex(8,256,176);
5992 clear_bitmap(scb.script_created_bitmaps[bitid].u_bmp);
5993 }
5994 }
5995
5996
5997
5998 void bmp_do_writer(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5999 {
6000 //sdci[1]=layer
6001 //sdci[2]=filename
6002 //sdci[3]=y
6003 //sdci[4]=font
6004 //sdci[5]=color
6005 //sdci[6]=bg color
6006 //sdci[7]=format_option
6007 //sdci[8]=string
6008 //sdci[9]=opacity
6009 //sdci[17] Bitmap Pointer
6010 //Z_scripterrlog("bitmap->Write() pointer is: %d\n", sdci[17]);
6011
6012 if ( sdci[17] <= 0 )
6013 {
6014 Z_scripterrlog("bitmap->Write() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
6015 return;
6016 }
6017 int32_t bitid = sdci[17] - 10;
6018
6019 if ( !scb.script_created_bitmaps[bitid].u_bmp )
6020 {
6021 Z_scripterrlog("Tried to write from an invalid bitmap pointer %d. Aborting. \n", sdci[17]);
6022 return;
6023 }
6024
6025 bool overwrite = (sdci[3] != 0);
6026 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
6027
6028 if(!str)
6029 {
6030 al_trace("String pointer is null! Internal error. \n");
6031 return;
6032 }
6033
6034 //char *cptr = new char[str->size()+1]; // +1 to account for \0 byte
6035 //std::strncpy(cptr, str->c_str(), str->size());
6036 //Z_scripterrlog("bitmap->Write extension matches ? : %s\n!", (FFCore.checkExtension(str->c_str(), ".png")) ? "true" : "false");
6037 //Z_scripterrlog("Trying to write filename %s\n", cptr);
6038 if
6039 (
6040 ( (FFCore.checkExtension(*str, "")) ) ||
6041 ( !(FFCore.checkExtension(*str, ".png")) && !(FFCore.checkExtension(*str, ".gif")) && !(FFCore.checkExtension(*str, ".bmp"))
6042 && !(FFCore.checkExtension(*str, ".pcx")) && !(FFCore.checkExtension(*str, ".tga")) )
6043 )
6044 {
6045 Z_scripterrlog("No extension, or invalid extension provided for writing bitmap file %s. Could not write the file.\nValid types are .png, .gif, .pcx, .tgx, and .bmp. Aborting.\n",str->c_str());
6046 }
6047 else if ( overwrite || (!checkPath(str->c_str(), false)) )
6048 {
6049 if(create_path(str->c_str()))
6050 {
6051 save_bitmap(str->c_str(), scb.script_created_bitmaps[bitid].u_bmp, RAMpal);
6052 if(checkPath(str->c_str(), false))
6053 {
6054 zprint("Wrote image file %s\n",str->c_str());
6055 }
6056 else
6057 {
6058 Z_scripterrlog("Failed to create file '%s'\n",str->c_str());
6059 }
6060 }
6061 else
6062 {
6063 Z_scripterrlog("Cannot write file '%s' because the directory does not exist, and could not be created.\n", str->c_str());
6064 }
6065 }
6066 else Z_scripterrlog("Cannot write file '%s' because the file already exists in the specified path.\n", str->c_str());
6067 }
6068
6069
6070 void bmp_do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6071 {
6072 //sdci[1]=layer
6073 //sdci[2]=x1
6074 //sdci[3]=y1
6075 //sdci[4]=x2
6076 //sdci[5]=y2
6077 //sdci[6]=x3
6078 //sdci[7]=y3
6079 //sdci[8]=x4
6080 //sdci[9]=y4
6081 //sdci[10]=width
6082 //sdci[11]=height
6083 //sdci[12]=cset
6084 //sdci[13]=flip
6085 //sdci[14]=tile/combo
6086 //sdci[15]=polytype
6087 //sdci[16] = other bitmap as texture
6088 //sdci[17] Bitmap Pointer
6089 Z_scripterrlog("bitmap quad pointer: %d\n", sdci[17]);
6090 if ( sdci[17] <= 0 )
6091 {
6092 Z_scripterrlog("bitmap->Quad() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
6093 return;
6094 }
6095 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
6096
6097 if ( !refbmp ) return;
6098
6099 int32_t x1 = sdci[2]/10000;
6100 int32_t y1 = sdci[3]/10000;
6101 int32_t x2 = sdci[4]/10000;
6102 int32_t y2 = sdci[5]/10000;
6103 int32_t x3 = sdci[6]/10000;
6104 int32_t y3 = sdci[7]/10000;
6105 int32_t x4 = sdci[8]/10000;
6106 int32_t y4 = sdci[9]/10000;
6107 int32_t w = sdci[10]/10000;
6108 int32_t h = sdci[11]/10000;
6109 int32_t color = sdci[12]/10000;
6110 int32_t flip=(sdci[13]/10000)&3;
6111 int32_t tile = sdci[14]/10000;
6112 int32_t polytype = sdci[15]/10000;
6113 int32_t quad_render_source = sdci[16]-10;
6114 //Z_scripterrlog("bitmap->Quad() render source is: %d\n", quad_render_source);
6115
6116 bool tex_is_bitmap = ( sdci[16] != 0 );
6117
6118 BITMAP *bmptexture=NULL;
6119 BITMAP *tex=NULL;
6120 polytype = vbound(polytype, 0, 14);
6121
6122 int32_t col[4];
6123 col[0]=col[1]=col[2]=col[3]=color;
6124 bool mustDestroyBmp = false;
6125
6126 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
6127
6128 if ( tex_is_bitmap )
6129 {
6130 bmptexture = FFCore.GetScriptBitmap(quad_render_source);
6131 if ( !bmptexture )
6132 {
6133 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
6134 tex_is_bitmap = 0;
6135 }
6136 }
6137
6138 if ( tex_is_bitmap )
6139 {
6140
6141 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
6142 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
6143 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", w);
6144 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", h);
6145
6146 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6147 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6148 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6149 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6150
6151 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
6152 }
6153 else
6154 {
6155 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6156 if(!tex)
6157 {
6158 //Z_scripterrlog("Bitmap->Quad() found an invalid texture bitmap.\n");
6159 mustDestroyBmp = true;
6160 tex = create_bitmap_ex(8, w*16, h*16);
6161 clear_bitmap(tex);
6162 }
6163
6164 if(tile > 0) // TILE
6165 {
6166 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6167 }
6168
6169 if ( tile < 0 ) // COMBO
6170 {
6171 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
6172 const int32_t tiletodraw = combo_tile(c, x1, y1);
6173 flip = flip ^ c.flip;
6174
6175 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6176 }
6177 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6178 {
6179 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6180 return; //non power of two error
6181 }
6182 //Z_scripterrlog("bitmap->Quad() is trying to blit from a bitmap texture.\n");
6183 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6184 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6185 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6186 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6187
6188 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
6189
6190 }
6191
6192
6193
6194
6195 //todo: finish palette shading
6196 /*
6197 POLYTYPE_FLAT
6198 POLYTYPE_GCOL
6199 POLYTYPE_GRGB
6200 POLYTYPE_ATEX
6201 POLYTYPE_PTEX
6202 POLYTYPE_ATEX_MASK
6203 POLYTYPE_PTEX_MASK
6204 POLYTYPE_ATEX_LIT
6205 POLYTYPE_PTEX_LIT
6206 POLYTYPE_ATEX_MASK_LIT
6207 POLYTYPE_PTEX_MASK_LIT
6208 POLYTYPE_ATEX_TRANS
6209 POLYTYPE_PTEX_TRANS
6210 POLYTYPE_ATEX_MASK_TRANS
6211 POLYTYPE_PTEX_MASK_TRANS
6212 */
6213
6214 if(mustDestroyBmp)
6215 destroy_bitmap(tex);
6216
6217 }
6218
6219
6220 void bmp_do_getpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6221 {
6222 //sdci[1]=layer
6223 //sdci[2]=x1
6224 //sdci[3]=y1
6225
6226 //sdci[17] Bitmap Pointer
6227 if ( sdci[17] <= 0 )
6228 {
6229 Z_scripterrlog("bitmap->GetPixel() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[17]);
6230 return;
6231 }
6232 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
6233 if ( refbmp == NULL ) return;
6234
6235
6236 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
6237
6238 int32_t x1 = sdci[2]/10000;
6239 int32_t y1 = (sdci[3]/10000)+yoffset;
6240 int32_t col = getpixel(scb.script_created_bitmaps[(sdci[17]-10)].u_bmp, x1, y1);
6241 Z_scripterrlog("bitmap->GetPixel col is %d\n",col);
6242 Z_scripterrlog("bitmap->GetPixel bitmap ptr is is %d\n",(sdci[17]-10));
6243 FFCore.set_sarg1(col);
6244 }
6245
6246
6247
6248
6249 void bmp_do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6250 {
6251 //sdci[1]=layer
6252 //sdci[2]=x1
6253 //sdci[3]=y1
6254 //sdci[4]=x2
6255 //sdci[5]=y2
6256 //sdci[6]=x3
6257 //sdci[7]=y3
6258 //sdci[8]=width
6259 //sdci[9]=height
6260 //sdci[10]=cset
6261 //sdci[11]=flip
6262 //sdci[12]=tile/combo
6263 //sdci[13]=polytype
6264 //sdci[17] Bitmap Pointer
6265 if ( sdci[17] <= 0 )
6266 {
6267 Z_scripterrlog("bitmap->Triangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
6268 return;
6269 }
6270 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
6271 if ( refbmp == NULL ) return;
6272
6273
6274 int32_t render_source = sdci[14]-10;
6275 //Z_scripterrlog("bitmap->Triangle() render source is: %d\n", render_source);
6276
6277 bool tex_is_bitmap = ( sdci[14] != 0 );
6278
6279 BITMAP *bmptexture=NULL;
6280 if ( tex_is_bitmap )
6281 {
6282 bmptexture = FFCore.GetScriptBitmap(render_source);
6283 if ( !bmptexture )
6284 {
6285 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
6286 tex_is_bitmap = 0;
6287 }
6288 }
6289
6290 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
6291
6292 int32_t x1 = sdci[2]/10000;
6293 int32_t y1 = sdci[3]/10000;
6294 int32_t x2 = sdci[4]/10000;
6295 int32_t y2 = sdci[5]/10000;
6296 int32_t x3 = sdci[6]/10000;
6297 int32_t y3 = sdci[7]/10000;
6298 int32_t w = sdci[8]/10000;
6299 int32_t h = sdci[9]/10000;
6300 int32_t color = sdci[10]/10000;
6301 int32_t flip=(sdci[11]/10000)&3;
6302 int32_t tile = sdci[12]/10000;
6303 int32_t polytype = sdci[13]/10000;
6304
6305 polytype = vbound(polytype, 0, 14);
6306 int32_t utex_w = w;
6307 int32_t utex_h = h;
6308
6309
6310 int32_t tex_width = w*16;
6311 int32_t tex_height = h*16;
6312
6313 bool mustDestroyBmp = false;
6314 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6315
6316 if(!tex)
6317 {
6318 mustDestroyBmp = true;
6319 tex = create_bitmap_ex(8, tex_width, tex_height);
6320 clear_bitmap(tex);
6321 }
6322
6323 int32_t col[3];
6324 /*
6325 if( color < 0 )
6326 {
6327 col[0]=draw_container.color_buffer[0];
6328 col[1]=draw_container.color_buffer[1];
6329 col[2]=draw_container.color_buffer[2];
6330 }
6331 else */
6332 {
6333 col[0]=col[1]=col[2]=color;
6334 }
6335
6336 if(tile > 0) // TILE
6337 {
6338 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6339 }
6340 else // COMBO
6341 {
6342 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
6343 const int32_t tiletodraw = combo_tile(c, x1, y1);
6344 flip = flip ^ c.flip;
6345
6346 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6347 }
6348 if ( !tex_is_bitmap )
6349 {
6350 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6351 {
6352 Z_message("bitmap->Triangle() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6353 return; //non power of two error
6354 }
6355 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6356 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
6357 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
6358
6359
6360 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
6361
6362 }
6363
6364 else
6365 {
6366 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6367 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6368 if ( !isPowerOfTwo(utex_h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_w);
6369 if ( !isPowerOfTwo(utex_w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_h);
6370
6371 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6372 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(utex_h), col[1] };
6373 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(utex_w), static_cast<float>(utex_h), col[2] };
6374
6375
6376 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
6377
6378 }
6379
6380 if(mustDestroyBmp)
6381 destroy_bitmap(tex);
6382 }
6383
6384
6385 void bmp_do_mode7r(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6386 {
6387 /*
6388 int32_t layer, int32_t rt, int32_t srcX, int32_t srcY, int32_t srcW, int32_t srcH, int32_t destW, int32_t destH, int32_t angle, int32_t cx, int32_t cy, int32_t space_z, int32_t horizon,
6389 int32_t scale_x, int32_t scale_y){
6390
6391 //sdci[1]=layer
6392 //sdci[2]=bitmap target
6393 //
6394 // -2 is the current Render Target
6395 // -1, this is the screen (framebuf).
6396 // 0: Render target 0
6397 // 1: Render target 1
6398 // 2: Render target 2
6399 // 3: Render target 3
6400 // 4: Render target 4
6401 // 5: Render target 5
6402 // 6: Render target 6
6403 // Otherwise: The pointer to a bitmap.
6404
6405 //sdci[3]=sourcex
6406 //sdci[4]=sourcey
6407 //sdci[5]=sourcew
6408 //sdci[6]=sourceh
6409
6410 //sdci[7]=destw
6411 //sdci[8]=desth
6412 //sdci[9]=angle
6413 //scdi[10] = pivot cx
6414 //sdci[11] = pivot cy
6415 //sdci[12] = space Z
6416 //sdci[13] = horizon
6417 //scdi[14] = scale X
6418 //scdi[15] = scale Y
6419 //sdci[16] = masked?
6420 //sdci[17] Bitmap Pointer
6421
6422
6423
6424 // ZScript-side constant values:
6425 const int32_t BITDX_NORMAL = 0;
6426 const int32_t BITDX_TRANS = 1; //Translucent
6427 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6428 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6429 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6430 //Note: Some modes cannot be combined. if a combination is not supported, an error
6431 // detailing this will be shown in allegro.log.
6432
6433 //scdi[15] = litcolour
6434 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6435 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6436
6437 //sdci[16]=mask
6438
6439 */
6440
6441
6442 int32_t bitmapIndex = sdci[2];
6443 int32_t usr_bitmap_index = sdci[2]-10;
6444 byte using_user_bitmap = 0;
6445 //Z_scripterrlog("bitmap index is: %d\n",bitmapIndex);
6446 //Z_scripterrlog("DrawPlane() bitmapIndex is: %d\n", bitmapIndex);
6447
6448 if ( bitmapIndex >= 10000 )
6449 {
6450 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
6451 }
6452 else if ( usr_bitmap_index > 0 )
6453 {
6454 bitmapIndex = usr_bitmap_index;
6455 using_user_bitmap = 1;
6456 // Z_scripterrlog("Mode7 is using a user bitmap target, pointer: %d\n", usr_bitmap_index);
6457 yoffset = 0;
6458 }
6459
6460 //int32_t sx = sdci[3]/10000;
6461 //int32_t sy = sdci[4]/10000;
6462 //int32_t sw = sdci[5]/10000;
6463 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
6464 //int32_t sh = sdci[6]/10000;
6465 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
6466 //int32_t dx = sdci[7]/10000;
6467 //int32_t dy = sdci[8]/10000;
6468 //int32_t dw = sdci[9]/10000;
6469 //int32_t dh = sdci[10]/10000;
6470 //float rot = sdci[11]/10000;
6471 //int32_t cx = sdci[12]/10000;
6472 //int32_t cy = sdci[13]/10000;
6473 //int32_t mode = sdci[14]/10000;
6474 //int32_t litcolour = sdci[15]/10000;
6475
6476 //rendering mode 7 args
6477 double srcX = sdci[3]/10000.0;
6478 double srcY = sdci[4]/10000.0;
6479 double destX = sdci[5]/10000.0;
6480 double destY = sdci[6]/10000.0;
6481
6482
6483 // int32_t srcW = sdci[5]/10000;
6484 // int32_t srcH = sdci[6]/10000;
6485 double destW = sdci[7]/10000.0;
6486 double destH = sdci[8]/10000.0;
6487 // int32_t angle = sdci[9]/10000;
6488 // int32_t cx = sdci[10]/10000;
6489 // int32_t cy = sdci[11]/10000;
6490 double space_z = sdci[9]/10000.0;
6491 double horizon = sdci[10]/10000.0;
6492 double scale_x = sdci[11]/10000.0;
6493 double scale_y = sdci[12]/10000.0;
6494 byte masked = ( sdci[13] ) ? 1 : 0;
6495
6496
6497 int32_t ref = 0;
6498
6499 //dx = 0 + xoffset;
6500 //dy = 0 + yoffset;
6501
6502 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
6503 //Do we need to also check the render target and do the same thing if the
6504 //dest == -2 and the render target is not RT_SCREEN?
6505
6506 ref = sdci[17];
6507 //Z_scripterrlog("bitmap->DrawPlane() ref id this frame is: %d\n", ref);
6508 ref -=10;
6509 //Z_scripterrlog("bitmap->DrawPlane() modified ref id this frame is: %d\n", ref);
6510
6511
6512 if ( ref <= 0 )
6513 {
6514 Z_scripterrlog("bitmap->DrawPlane() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6515 return;
6516 }
6517 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
6518
6519 if(!sourceBitmap)
6520 {
6521 Z_message("Warning: %d->DrawPlane() source bitmap contains invalid data or is not initialized.\n", ref);
6522 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6523 return;
6524 }
6525
6526 BITMAP *destBMP=NULL;
6527 //zprint2("mode 7 bitmap index is: %d\n",bitmapIndex);
6528 switch(bitmapIndex)
6529 {
6530 case -2:
6531 {
6532 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6533 //zprint2("current RT is: %d\n", curr_rt);
6534 if ( curr_rt >= 0 && curr_rt < 7 )
6535 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6536 else destBMP = bmp; //screen
6537 break;
6538 }
6539 case -1:
6540 destBMP = bmp; //this is framebuf, by default
6541 break;
6542 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
6543 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
6544 //destBMP = framebuf; //Drawing to the screen.
6545 //break;
6546
6547 //1 through 6 are the old system bitmaps (Render Targets)
6548 case 0:
6549 case 1:
6550 case 2:
6551 case 3:
6552 case 4:
6553 case 5:
6554 case 6:
6555 {
6556 //This gets a render target.
6557 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
6558
6559 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6560 //sdci[18] = bitmapIndex;
6561 break;
6562 }
6563 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6564 default:
6565 {
6566 destBMP = scb.script_created_bitmaps[usr_bitmap_index].u_bmp;
6567 //sdci[18] = usr_bitmap_index;
6568 if ( !scb.script_created_bitmaps[usr_bitmap_index].u_bmp )
6569 {
6570 Z_scripterrlog("Target for bitmap->DrawPlane is uninitialised. Aborting.\n");
6571 break;
6572 }
6573 }
6574 //FFCore.get_user_bitmap(bitmapIndex); break;
6575 }
6576
6577 if (!destBMP)
6578 {
6579 Z_message("Warning: DrawPlane(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6580 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6581 return;
6582 }
6583
6584 //dx = dx + xoffset; //don't do this here!
6585 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6586 //All of these are a factor of 10000 as fix.
6587 int32_t screen_x = 0; int32_t screen_y = 0;
6588
6589 double distance = 0; double horizontal_scale = 0;
6590
6591 int32_t screen_y_horizon = 0;
6592
6593 double line_dx = 0; double line_dy = 0;
6594
6595 int32_t space_x = 0; int32_t space_y = 0;
6596
6597 for(screen_y = 0; screen_y < destH; screen_y++) //fix, offset by .0000
6598 {
6599 //Calculate the distance of each line from the camera point
6600 screen_y_horizon = screen_y + horizon;
6601
6602 distance = ((space_z * scale_y) / ((screen_y_horizon != 0) ? screen_y_horizon : 1));
6603
6604 //Get the scale of each line based on the distance
6605
6606 horizontal_scale = (distance / (( scale_x != 0 ) ? scale_x : 1));
6607
6608 //There was some math here before I stripped out the rotation step
6609 line_dx = horizontal_scale;
6610 line_dy = 0;
6611
6612 //space_x,space_y - where to grab each scanline from on the space bitmap
6613 space_x = srcX - destW/2.0 * line_dx;
6614 space_y = srcY - distance + destH/2.0 * line_dy;
6615
6616 //Keep blits within the bounds of both bitmaps to avoid crashes
6617 int32_t y1 = srcY+space_y;
6618 int32_t y2 = destY+screen_y;
6619 if(y1 >=0 && y1 <= (sourceBitmap->h-1) && y2 >=0 && y2 <= (destBMP->h-1) )
6620 {
6621 if ( masked ) masked_stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6622 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6623 else stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6624 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6625 }
6626 }
6627 }
6628
6629
6630 //Draw]()
6631 6787 void bmp_do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6632 {
6633 /*
6634 //sdci[1]=layer
6635 //sdci[2]=bitmap target
6636 //
6637 // -2 is the current Render Target
6638 // -1, this is the screen (framebuf).
6639 // 0: Render target 0
6640 // 1: Render target 1
6641 // 2: Render target 2
6642 // 3: Render target 3
6643 // 4: Render target 4
6644 // 5: Render target 5
6645 // 6: Render target 6
6646 // Otherwise: The pointer to a bitmap.
6647
6648 //sdci[3]=sourcex
6649 //sdci[4]=sourcey
6650 //sdci[5]=sourcew
6651 //sdci[6]=sourceh
6652 //sdci[7]=destx
6653 //sdci[8]=desty
6654 //sdci[9]=destw
6655 //sdci[10]=desth
6656 //sdci[11]=rotation/angle
6657 //scdi[12] = pivot cx
6658 //sdci[13] = pivot cy
6659 //scdi[14] = effect flags
6660 //sdci[17] Bitmap Pointer
6661
6662 // ZScript-side constant values:
6663 const int32_t BITDX_NORMAL = 0;
6664 const int32_t BITDX_TRANS = 1; //Translucent
6665 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6666 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6667 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6668 //Note: Some modes cannot be combined. if a combination is not supported, an error
6669 // detailing this will be shown in allegro.log.
6670
6671 //scdi[15] = litcolour
6672 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6673 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6674
6675 //sdci[16]=mask
6676
6677 */
6678
6679 6787 int32_t bitmapIndex = sdci[2]/10000;
6680 6787 int32_t usr_bitmap_index = sdci[2]-10;
6681 6787 byte using_user_bitmap = 0;
6682 //Z_scripterrlog("bitmap index is: %d\n",bitmapIndex);
6683 //Z_scripterrlog("Blit() bitmapIndex is: %d\n", bitmapIndex);
6684 #if LOG_BMPBLIT_LEVEL > 0
6685 Z_scripterrlog("Blit() found a dest bitmap ID of: %d\n",bitmapIndex);
6686 #endif
6687
1/2
✓ Branch 0 taken 6787 times.
✗ Branch 1 not taken.
6787 if ( bitmapIndex > 10000 )
6688 {
6689 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
6690 }
6691
3/4
✓ Branch 0 taken 195 times.
✓ Branch 1 taken 6592 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 195 times.
6787 if ( usr_bitmap_index > 0 && usr_bitmap_index < 10000 )
6692 {
6693 195 bitmapIndex = usr_bitmap_index;
6694 195 using_user_bitmap = 1;
6695 195 yoffset = 0;
6696 195 }
6697
6698 6787 int32_t sx = sdci[3]/10000;
6699 6787 int32_t sy = sdci[4]/10000;
6700 6787 int32_t sw = sdci[5]/10000;
6701 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
6702 6787 int32_t sh = sdci[6]/10000;
6703 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
6704 6787 int32_t dx = sdci[7]/10000;
6705 6787 int32_t dy = sdci[8]/10000;
6706 6787 int32_t dw = sdci[9]/10000;
6707 6787 int32_t dh = sdci[10]/10000;
6708 6787 float rot = sdci[11]/10000;
6709 6787 int32_t cx = sdci[12]/10000;
6710 6787 int32_t cy = sdci[13]/10000;
6711 6787 int32_t mode = sdci[14]/10000;
6712 6787 int32_t litcolour = sdci[15]/10000;
6713 6787 bool masked = (sdci[16] != 0);
6714
6715 6787 int32_t ref = 0;
6716
6717 6787 dx = dx + xoffset;
6718 6787 dy = dy + yoffset;
6719
6720
2/4
✓ Branch 0 taken 6787 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6787 times.
6787 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
6721 //Do we need to also check the render target and do the same thing if the
6722 //dest == -2 and the render target is not RT_SCREEN?
6723
6724 6787 ref = sdci[17];
6725 //Z_scripterrlog("bitmap->blit() ref id this frame is: %d\n", ref);
6726 6787 ref -=10;
6727 //Z_scripterrlog("bitmap->blit() modified ref id this frame is: %d\n", ref);
6728
6729
6730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6787 times.
6787 if ( ref <= 0 )
6731 {
6732 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6733 return;
6734 }
6735 6787 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
6736 #if LOG_BMPBLIT_LEVEL > 0
6737 Z_scripterrlog("bitmap->Blit() is trying to blit to ref: %d\n",sdci[17]);
6738 #endif
6739
1/2
✓ Branch 0 taken 6787 times.
✗ Branch 1 not taken.
6787 if(!sourceBitmap)
6740 {
6741
6742 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
6743 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6744 return;
6745 }
6746
6747 6787 BITMAP *destBMP=NULL;
6748 //zprint2("blit () bitmap index is: %d\n",bitmapIndex);
6749
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 195 times.
✓ Branch 2 taken 786 times.
✓ Branch 3 taken 5806 times.
6787 switch(bitmapIndex)
6750 {
6751 case -2:
6752 {
6753 786 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6754 //zprint2("current RT is: %d\n", curr_rt);
6755
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 786 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
786 if ( curr_rt >= 0 && curr_rt < 7 )
6756 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6757 786 else destBMP = bmp; //screen
6758 786 break;
6759 }
6760 case -1:
6761 5806 destBMP = bmp; //this is framebuf, by default
6762 5806 break;
6763 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
6764 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
6765 //destBMP = framebuf; //Drawing to the screen.
6766 //break;
6767
6768 //1 through 6 are the old system bitmaps (Render Targets)
6769 case 0:
6770 case 1:
6771 case 2:
6772 case 3:
6773 case 4:
6774 case 5:
6775 case 6:
6776 {
6777 //This gets a render target.
6778 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
6779
6780 //destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6781 //sdci[18] = bitmapIndex;
6782 break;
6783 }
6784 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6785 default:
6786 {
6787 195 destBMP = scb.script_created_bitmaps[usr_bitmap_index].u_bmp;
6788 //sdci[18] = usr_bitmap_index;
6789
1/2
✓ Branch 0 taken 195 times.
✗ Branch 1 not taken.
195 if ( !scb.script_created_bitmaps[usr_bitmap_index].u_bmp )
6790 {
6791 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
6792 break;
6793 }
6794 }
6795 //FFCore.get_user_bitmap(bitmapIndex); break;
6796 195 }
6797
6798
6799
6800 #if LOG_BMPBLIT_LEVEL > 0
6801 Z_scripterrlog("bitmap->Blit() is trying to blit to dest bitmap ID: %d\n",bitmapIndex);
6802 #endif
6803
6804
6805
1/2
✓ Branch 0 taken 6787 times.
✗ Branch 1 not taken.
6787 if (!destBMP)
6806 {
6807
6808 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6809 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6810 return;
6811 }
6812
6813 //bugfix
6814 //sx = vbound(sx, 0, sourceBitmap->w);
6815 #if LOG_BMPBLIT_LEVEL > 0
6816 Z_scripterrlog("Blit %s is: %d\n", "sx", sx);
6817 Z_scripterrlog("Blit %s is: %d\n", "source->w", sourceBitmap->w);
6818 #endif
6819 //sy = vbound(sy, 0, sourceBitmap->h);
6820 #if LOG_BMPBLIT_LEVEL > 0
6821 Z_scripterrlog("Blit %s is: %d\n", "sy", sy);
6822 Z_scripterrlog("Blit %s is: %d\n", "source->h", sourceBitmap->h);
6823 #endif
6824 //sw = vbound(sw, 0, sourceBitmap->w - sx); //keep the w/h within range as well
6825 #if LOG_BMPBLIT_LEVEL > 0
6826 Z_scripterrlog("Blit %s is: %d\n", "sw", sw);
6827 #endif
6828 //sh = vbound(sh, 0, sourceBitmap->h - sy);
6829 #if LOG_BMPBLIT_LEVEL > 0
6830 Z_scripterrlog("Blit %s is: %d\n", "sh", sh);
6831
6832 Z_scripterrlog("Blit %s is: %d\n", "dh", dh);
6833 Z_scripterrlog("Blit %s is: %d\n", "dw", dw);
6834 #endif
6835
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 6676 times.
6787 bool stretched = (sw != dw || sh != dh);
6836 //bool stretched = (sourceBitmap->w != destBMP->w || sourceBitmap->h != destBMP->h);
6837 #if LOG_BMPBLIT_LEVEL > 0
6838 Z_scripterrlog("Blit %s is: %s\n", "stretched", stretched ? "true" : "false");
6839 #endif
6840 //BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
6841
6842
6843
6844
6845
6846 6787 BITMAP* subBmp = 0;
6847
6848 /* IDR what this was. -Z ( 17th April, 2019 )
6849 if ( bitmapIndex == -1 ) {
6850 blit(bmp, sourceBitmap, sx, sy, 0, 0, dw, dh);
6851 }
6852 */
6853
6854
2/4
✓ Branch 0 taken 6787 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6787 times.
6787 if(rot != 0 || mode != 0)
6855 {
6856 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
6857 clear_bitmap(subBmp);
6858
6859 if(!subBmp)
6860 {
6861
6862 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
6863 return;
6864 }
6865 }
6866 6787 BITMAP* sbmp = sourceBitmap;
6867
2/4
✓ Branch 0 taken 6787 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6787 times.
6787 if (sx + sw > sbmp->w || sy + sh > sbmp->h)
6868 {
6869 sbmp = create_bitmap_ex(8, sw, sh);
6870 clear_bitmap(sbmp);
6871 blit(sourceBitmap, sbmp, sx, sy, 0, 0, std::min(sourceBitmap->w-sx, sw), std::min(sourceBitmap->h-sy, sh));
6872 sx = 0;
6873 sy = 0;
6874 }
6875 //dx = dx + xoffset; //don't do this here!
6876 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6877
6878
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 6676 times.
6787 if(stretched)
6879 {
6880
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
111 if(masked)
6881 { //stretched and masked
6882 if ( rot == 0 )
6883 { //if not rotated
6884 switch(mode)
6885 {
6886 case 1:
6887 //transparent
6888 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6889 draw_trans_sprite(destBMP, subBmp, dx, dy);
6890 break;
6891
6892
6893 case 2:
6894 //pivot?
6895 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6896 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6897 //Pivoting requires two more args
6898 break;
6899
6900 case 3:
6901 //pivot + trans
6902 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6903 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6904 break;
6905
6906 case 4:
6907 //flip v
6908 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6909 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
6910 break;
6911
6912 case 5:
6913 //trans + v flip
6914 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6915 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
6916 break;
6917
6918 case 6:
6919 //pivot + v flip
6920 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6921 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6922 break;
6923
6924 case 8:
6925 //vlip h
6926 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6927 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
6928 break;
6929
6930 case 9:
6931 //trans + h flip
6932 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6933 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
6934 break;
6935
6936 case 10:
6937 //flip H and pivot
6938 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6939 //return error cannot pivot and h flip
6940 break;
6941
6942 case 12:
6943 //vh flip
6944 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6945 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
6946 break;
6947
6948 case 13:
6949 //trans + vh flip
6950 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6951 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
6952 break;
6953
6954 case 14:
6955 //pivot and vh flip
6956 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6957 //return error cannot both pivot and vh flip
6958 break;
6959
6960 case 16:
6961 //lit
6962 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6963 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
6964 break;
6965
6966 case 18:
6967 //pivot, lit
6968 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6969 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6970 break;
6971
6972 case 20:
6973 //lit + v flip
6974 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6975 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
6976 break;
6977
6978 case 22:
6979 //Pivot, vflip, lit
6980 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6981 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6982 break;
6983
6984 case 24:
6985 //lit + h flip
6986 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6987 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
6988 break;
6989
6990 case 26:
6991 //pivot + lit + hflip
6992 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
6993 //return error cannot pivot, lit, and flip
6994 break;
6995
6996 case 28:
6997 //lit + vh flip
6998 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6999 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7000 break;
7001
7002 case 32: //gouraud
7003 //Probably not wort supporting.
7004 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7005 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7006 break;
7007
7008 case 0:
7009 //no effect
7010 masked_stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
7011 break;
7012
7013
7014 default:
7015
7016 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7017
7018
7019 }
7020 } //end if not rotated
7021
7022 if ( rot != 0 ) //if rotated
7023 {
7024 switch(mode)
7025 {
7026 case 1:
7027 //transparent
7028 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7029 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7030
7031 break;
7032
7033 case 2:
7034 //pivot?
7035 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7036 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7037 //Pivoting requires two more args
7038 break;
7039
7040 case 3:
7041 //pivot + trans
7042 //return an error, cannot both rotate and pivot
7043 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7044 break;
7045
7046 case 4:
7047 //flip v
7048 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7049 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7050 break;
7051
7052 case 5:
7053 //trans + v flip
7054 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7055 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7056 break;
7057
7058 case 6:
7059 //pivot + v flip
7060 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7061 //return an error, cannot both rotate and pivot
7062 break;
7063
7064 case 8:
7065 //flip h
7066 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7067 //return an error, cannot both rotate and flip H
7068 break;
7069
7070 case 9:
7071 //trans + h flip
7072 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7073 //return an error, cannot rotate and flip a trans sprite
7074 break;
7075
7076 case 10:
7077 //flip H and pivot
7078 //return error cannot pivot and h flip
7079 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7080 break;
7081
7082 case 12:
7083 //vh flip
7084 //return an error, cannot rotate and VH flip a trans sprite
7085 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7086 break;
7087
7088 case 13:
7089 //trans + vh flip
7090 //return an error, cannot rotate and VH flip a trans sprite
7091 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7092 break;
7093
7094 case 14:
7095 //pivot and vh flip
7096 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7097 //return error cannot both pivot and vh flip
7098 break;
7099
7100 case 16:
7101 //lit
7102 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7103 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7104 break;
7105
7106 case 18:
7107 //pivot, lit
7108 //return an error, cannot both rotate and pivot
7109 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7110 break;
7111
7112 case 20:
7113 //lit + vflip
7114 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7115 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7116 break;
7117
7118 case 22:
7119 //Pivot, vflip, lit
7120 //return an error, cannot both rotate and pivot
7121 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7122 break;
7123
7124 case 24:
7125 //lit + h flip
7126 //return an error, cannot both rotate and H flip
7127 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7128 break;
7129
7130 case 26:
7131 //pivot + lit + hflip
7132 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7133 //return error cannot pivot, lit, and flip
7134 break;
7135
7136 case 28:
7137 //lit + vh flip
7138 //return an error, cannot both rotate and VH flip
7139 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7140 break;
7141
7142 case 32: //gouraud
7143 //Probably not wort supporting.
7144 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7145 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7146 break;
7147
7148 case 0:
7149 //no effect.
7150 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7151 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7152 break;
7153
7154 default:
7155
7156 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7157
7158 }
7159 }
7160 } //end if stretched and masked
7161
7162 else //stretched, not masked
7163 {
7164
7165
7166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
111 if ( rot == 0 ) //if not rotated
7167 {
7168
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 111 times.
111 switch(mode)
7169 {
7170 case 1:
7171 //transparent
7172 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7173 draw_trans_sprite(destBMP, subBmp, dx, dy);
7174 break;
7175
7176
7177 case 2:
7178 //pivot?
7179 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7180 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7181 //Pivoting requires two more args
7182 break;
7183
7184 case 3:
7185 //pivot + trans
7186 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7187 pivot_sprite_trans(destBMP, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
7188 break;
7189
7190 case 4:
7191 //flip v
7192 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7193 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7194 break;
7195
7196 case 5:
7197 //trans + v flip
7198 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7199 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7200 break;
7201
7202 case 6:
7203 //pivot + v flip
7204 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7205 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7206 break;
7207
7208 case 8:
7209 //vlip h
7210 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7211 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7212 break;
7213
7214 case 9:
7215 //trans + h flip
7216 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7217 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7218 break;
7219
7220 case 10:
7221 //flip H and pivot
7222 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7223 //return error cannot pivot and h flip
7224 break;
7225
7226 case 12:
7227 //vh flip
7228 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7229 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7230 break;
7231
7232 case 13:
7233 //trans + vh flip
7234 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7235 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7236 break;
7237
7238 case 14:
7239 //pivot and vh flip
7240 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7241 //return error cannot both pivot and vh flip
7242 break;
7243
7244 case 16:
7245 //lit
7246 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7247 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7248 break;
7249
7250 case 18:
7251 //pivot, lit
7252 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7253 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7254 break;
7255
7256 case 20:
7257 //lit + v flip
7258 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7259 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7260 break;
7261
7262 case 22:
7263 //Pivot, vflip, lit
7264 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7265 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7266 break;
7267
7268 case 24:
7269 //lit + h flip
7270 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7271 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7272 break;
7273
7274 case 26:
7275 //pivot + lit + hflip
7276 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7277 //return error cannot pivot, lit, and flip
7278 break;
7279
7280 case 28:
7281 //lit + vh flip
7282 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7283 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7284 break;
7285
7286 case 32: //gouraud
7287 //Probably not wort supporting.
7288 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7289 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7290 break;
7291
7292 case 0:
7293 //no effect
7294 111 stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
7295 111 break;
7296
7297
7298 default:
7299
7300 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7301
7302
7303 }
7304 111 } //end if not rotated
7305
7306
1/2
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
111 if ( rot != 0 ) //if rotated
7307 {
7308 switch(mode)
7309 {
7310 case 1:
7311 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7312 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7313
7314 break;
7315
7316 case 2:
7317 //pivot?
7318 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7319 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7320 //Pivoting requires two more args
7321 break;
7322
7323 case 3:
7324 //pivot + trans
7325 //return an error, cannot both rotate and pivot
7326 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7327 break;
7328
7329 case 4:
7330 //flip v
7331 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7332 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7333 break;
7334
7335 case 5:
7336 //trans + v flip
7337 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7338 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7339 break;
7340
7341 case 6:
7342 //pivot + v flip
7343 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7344 //return an error, cannot both rotate and pivot
7345 break;
7346
7347 case 8:
7348 //flip h
7349 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7350 //return an error, cannot both rotate and flip H
7351 break;
7352
7353 case 9:
7354 //trans + h flip
7355 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7356 //return an error, cannot rotate and flip a trans sprite
7357 break;
7358
7359 case 10:
7360 //flip H and pivot
7361 //return error cannot pivot and h flip
7362 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7363 break;
7364
7365 case 12:
7366 //vh flip
7367 //return an error, cannot rotate and VH flip a trans sprite
7368 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7369 break;
7370
7371 case 13:
7372 //trans + vh flip
7373 //return an error, cannot rotate and VH flip a trans sprite
7374 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7375 break;
7376
7377 case 14:
7378 //pivot and vh flip
7379 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7380 //return error cannot both pivot and vh flip
7381 break;
7382
7383 case 16:
7384 //lit
7385 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7386 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7387 break;
7388
7389 case 18:
7390 //pivot, lit
7391 //return an error, cannot both rotate and pivot
7392 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7393 break;
7394
7395 case 20:
7396 //lit + vflip
7397 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7398 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7399 break;
7400
7401 case 22:
7402 //Pivot, vflip, lit
7403 //return an error, cannot both rotate and pivot
7404 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7405 break;
7406
7407 case 24:
7408 //lit + h flip
7409 //return an error, cannot both rotate and H flip
7410 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7411 break;
7412
7413 case 26:
7414 //pivot + lit + hflip
7415 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7416 //return error cannot pivot, lit, and flip
7417 break;
7418
7419 case 28:
7420 //lit + vh flip
7421 //return an error, cannot both rotate and VH flip
7422 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7423 break;
7424
7425 case 32: //gouraud
7426 //Probably not wort supporting.
7427 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7428 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7429 break;
7430
7431 case 0:
7432 //no effect.
7433 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7434 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7435 break;
7436
7437 default:
7438
7439 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7440
7441 }
7442 }
7443
7444 } //end if stretched, but not masked
7445 111 }
7446 else //not stretched
7447 {
7448
7449
2/2
✓ Branch 0 taken 6481 times.
✓ Branch 1 taken 195 times.
6676 if(masked) //if masked, but not stretched
7450 {
7451
7452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6481 times.
6481 if ( rot == 0 ) //if not rotated
7453 {
7454
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 6481 times.
6481 switch(mode)
7455 {
7456 case 1:
7457 //transparent
7458 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7459 draw_trans_sprite(destBMP, subBmp, dx, dy);
7460 break;
7461
7462
7463 case 2:
7464 //pivot?
7465 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7466 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7467 //Pivoting requires two more args
7468 break;
7469
7470 case 3:
7471 //pivot + trans
7472 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7473 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7474 break;
7475
7476 case 4:
7477 //flip v
7478 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7479 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7480 break;
7481
7482 case 5:
7483 //trans + v flip
7484 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7485 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7486 break;
7487
7488 case 6:
7489 //pivot + v flip
7490 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7491 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7492 break;
7493
7494 case 8:
7495 //vlip h
7496 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7497 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7498 break;
7499
7500 case 9:
7501 //trans + h flip
7502 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7503 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7504 break;
7505
7506 case 10:
7507 //flip H and pivot
7508 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7509 //return error cannot pivot and h flip
7510 break;
7511
7512 case 12:
7513 //vh flip
7514 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7515 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7516 break;
7517
7518 case 13:
7519 //trans + vh flip
7520 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7521 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7522 break;
7523
7524 case 14:
7525 //pivot and vh flip
7526 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7527 //return error cannot both pivot and vh flip
7528 break;
7529
7530 case 16:
7531 //lit
7532 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7533 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7534 break;
7535
7536 case 18:
7537 //pivot, lit
7538 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7539 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7540 break;
7541
7542 case 20:
7543 //lit + v flip
7544 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7545 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7546 break;
7547
7548 case 22:
7549 //Pivot, vflip, lit
7550 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7551 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7552 break;
7553
7554 case 24:
7555 //lit + h flip
7556 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7557 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7558 break;
7559
7560 case 26:
7561 //pivot + lit + hflip
7562 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7563 //return error cannot pivot, lit, and flip
7564 break;
7565
7566 case 28:
7567 //lit + vh flip
7568 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7569 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7570 break;
7571
7572 case 32: //gouraud
7573 //Probably not wort supporting.
7574 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7575 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7576 break;
7577
7578 case 0:
7579 //no effect
7580 6481 masked_blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7581 6481 break;
7582
7583
7584 default:
7585
7586 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7587
7588
7589 }
7590 6481 } //end if not rotated
7591
7592
1/2
✓ Branch 0 taken 6481 times.
✗ Branch 1 not taken.
6481 if ( rot != 0 ) //if rotated
7593 {
7594 switch(mode)
7595 {
7596 case 1:
7597 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //transparent
7598 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7599
7600 break;
7601
7602 case 2:
7603 //pivot?
7604 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7605 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7606 //Pivoting requires two more args
7607 break;
7608
7609 case 3:
7610 //pivot + trans
7611 //return an error, cannot both rotate and pivot
7612 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7613 break;
7614
7615 case 4:
7616 //flip v
7617 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7618 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7619 break;
7620
7621 case 5:
7622 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
7623 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7624 break;
7625
7626 case 6:
7627 //pivot + v flip
7628 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7629 //return an error, cannot both rotate and pivot
7630 break;
7631
7632 case 8:
7633 //flip h
7634 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7635 //return an error, cannot both rotate and flip H
7636 break;
7637
7638 case 9:
7639 //trans + h flip
7640 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7641 //return an error, cannot rotate and flip a trans sprite
7642 break;
7643
7644 case 10:
7645 //flip H and pivot
7646 //return error cannot pivot and h flip
7647 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7648 break;
7649
7650 case 12:
7651 //vh flip
7652 //return an error, cannot rotate and VH flip a trans sprite
7653 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7654 break;
7655
7656 case 13:
7657 //trans + vh flip
7658 //return an error, cannot rotate and VH flip a trans sprite
7659 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7660 break;
7661
7662 case 14:
7663 //pivot and vh flip
7664 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7665 //return error cannot both pivot and vh flip
7666 break;
7667
7668 case 16:
7669 //lit
7670 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7671 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7672 break;
7673
7674 case 18:
7675 //pivot, lit
7676 //return an error, cannot both rotate and pivot
7677 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7678 break;
7679
7680 case 20:
7681 //lit + vflip
7682 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7683 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7684 break;
7685
7686 case 22:
7687 //Pivot, vflip, lit
7688 //return an error, cannot both rotate and pivot
7689 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7690 break;
7691
7692 case 24:
7693 //lit + h flip
7694 //return an error, cannot both rotate and H flip
7695 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7696 break;
7697
7698 case 26:
7699 //pivot + lit + hflip
7700 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7701 //return error cannot pivot, lit, and flip
7702 break;
7703
7704 case 28:
7705 //lit + vh flip
7706 //return an error, cannot both rotate and VH flip
7707 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7708 break;
7709
7710 case 32: //gouraud
7711 //Probably not wort supporting.
7712 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7713 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7714 break;
7715
7716 case 0:
7717 //no effect.
7718 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7719 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7720 break;
7721
7722 default:
7723
7724 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7725
7726 }
7727 } //end rtated, masked
7728 6481 } //end if masked
7729
7730 else //not masked, and not stretched; just blit
7731 {
7732
7733
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 195 times.
195 if ( rot == 0 ) //if not rotated
7734 {
7735
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 195 times.
195 switch(mode)
7736 {
7737 case 1:
7738 //transparent
7739 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7740 draw_trans_sprite(destBMP, subBmp, dx, dy);
7741 break;
7742
7743
7744 case 2:
7745 //pivot?
7746 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7747 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7748 //Pivoting requires two more args
7749 break;
7750
7751 case 3:
7752 //pivot + trans
7753 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7754 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7755 break;
7756
7757 case 4:
7758 //flip v
7759 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7760 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7761 break;
7762
7763 case 5:
7764 //trans + v flip
7765 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7766 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7767 break;
7768
7769 case 6:
7770 //pivot + v flip
7771 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7772 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7773 break;
7774
7775 case 8:
7776 //vlip h
7777 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7778 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7779 break;
7780
7781 case 9:
7782 //trans + h flip
7783 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7784 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7785 break;
7786
7787 case 10:
7788 //flip H and pivot
7789 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7790 //return error cannot pivot and h flip
7791 break;
7792
7793 case 12:
7794 //vh flip
7795 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7796 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7797 break;
7798
7799 case 13:
7800 //trans + vh flip
7801 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7802 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7803 break;
7804
7805 case 14:
7806 //pivot and vh flip
7807 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7808 //return error cannot both pivot and vh flip
7809 break;
7810
7811 case 16:
7812 //lit
7813 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7814 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7815 break;
7816
7817 case 18:
7818 //pivot, lit
7819 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7820 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7821 break;
7822
7823 case 20:
7824 //lit + v flip
7825 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7826 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7827 break;
7828
7829 case 22:
7830 //Pivot, vflip, lit
7831 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7832 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7833 break;
7834
7835 case 24:
7836 //lit + h flip
7837 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7838 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7839 break;
7840
7841 case 26:
7842 //pivot + lit + hflip
7843 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7844 //return error cannot pivot, lit, and flip
7845 break;
7846
7847 case 28:
7848 //lit + vh flip
7849 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7850 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7851 break;
7852
7853 case 32: //gouraud
7854 //Probably not wort supporting.
7855 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7856 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7857 break;
7858
7859 case 0:
7860 //no effect
7861 195 blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7862 195 break;
7863
7864
7865 default:
7866
7867 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7868
7869
7870 }
7871 195 } //end if not rotated
7872
7873
1/2
✓ Branch 0 taken 195 times.
✗ Branch 1 not taken.
195 if ( rot != 0 ) //if rotated
7874 {
7875 switch(mode)
7876 {
7877 case 1:
7878 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);//transparent
7879 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7880
7881 break;
7882
7883 case 2:
7884 //pivot?
7885 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7886 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7887 //Pivoting requires two more args
7888 break;
7889
7890 case 3:
7891 //pivot + trans
7892 //return an error, cannot both rotate and pivot
7893 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7894 break;
7895
7896 case 4:
7897 //flip v
7898 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7899 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7900 break;
7901
7902 case 5:
7903 //trans + v flip
7904 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7905 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7906 break;
7907
7908 case 6:
7909 //pivot + v flip
7910 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7911 //return an error, cannot both rotate and pivot
7912 break;
7913
7914 case 8:
7915 //flip h
7916 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7917 //return an error, cannot both rotate and flip H
7918 break;
7919
7920 case 9:
7921 //trans + h flip
7922 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7923 //return an error, cannot rotate and flip a trans sprite
7924 break;
7925
7926 case 10:
7927 //flip H and pivot
7928 //return error cannot pivot and h flip
7929 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7930 break;
7931
7932 case 12:
7933 //vh flip
7934 //return an error, cannot rotate and VH flip a trans sprite
7935 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7936 break;
7937
7938 case 13:
7939 //trans + vh flip
7940 //return an error, cannot rotate and VH flip a trans sprite
7941 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7942 break;
7943
7944 case 14:
7945 //pivot and vh flip
7946 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7947 //return error cannot both pivot and vh flip
7948 break;
7949
7950 case 16:
7951 //lit
7952 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7953 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7954 break;
7955
7956 case 18:
7957 //pivot, lit
7958 //return an error, cannot both rotate and pivot
7959 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7960 break;
7961
7962 case 20:
7963 //lit + vflip
7964 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7965 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7966 break;
7967
7968 case 22:
7969 //Pivot, vflip, lit
7970 //return an error, cannot both rotate and pivot
7971 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7972 break;
7973
7974 case 24:
7975 //lit + h flip
7976 //return an error, cannot both rotate and H flip
7977 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7978 break;
7979
7980 case 26:
7981 //pivot + lit + hflip
7982 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7983 //return error cannot pivot, lit, and flip
7984 break;
7985
7986 case 28:
7987 //lit + vh flip
7988 //return an error, cannot both rotate and VH flip
7989 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7990 break;
7991
7992 case 32: //gouraud
7993 //Probably not wort supporting.
7994 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7995 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7996 break;
7997
7998 case 0:
7999 //no effect.
8000 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
8001 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
8002 break;
8003
8004 default:
8005
8006 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8007
8008 }
8009 } //end if rotated
8010 } //end if not masked
8011 } //end if not stretched
8012
8013 //cleanup
8014
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6787 times.
6787 if(subBmp)
8015 {
8016 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
8017 destroy_bitmap(subBmp);
8018 }
8019
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6787 times.
6787 if (sbmp != sourceBitmap)
8020 {
8021 destroy_bitmap(sbmp);
8022 }
8023 6787 }
8024
8025
8026
8027 3 void bmp_do_blittor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
8028 {
8029 /*
8030 //sdci[1]=layer
8031 //sdci[2]=bitmap target
8032 //
8033 // -2 is the current Render Target
8034 // -1, this is the screen (framebuf).
8035 // 0: Render target 0
8036 // 1: Render target 1
8037 // 2: Render target 2
8038 // 3: Render target 3
8039 // 4: Render target 4
8040 // 5: Render target 5
8041 // 6: Render target 6
8042 // Otherwise: The pointer to a bitmap.
8043
8044 //sdci[3]=sourcex
8045 //sdci[4]=sourcey
8046 //sdci[5]=sourcew
8047 //sdci[6]=sourceh
8048 //sdci[7]=destx
8049 //sdci[8]=desty
8050 //sdci[9]=destw
8051 //sdci[10]=desth
8052 //sdci[11]=rotation/angle
8053 //scdi[12] = pivot cx
8054 //sdci[13] = pivot cy
8055 //scdi[14] = effect flags
8056 //sdci[17] Bitmap Pointer
8057
8058 // ZScript-side constant values:
8059 const int32_t BITDX_NORMAL = 0;
8060 const int32_t BITDX_TRANS = 1; //Translucent
8061 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
8062 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
8063 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
8064 //Note: Some modes cannot be combined. if a combination is not supported, an error
8065 // detailing this will be shown in allegro.log.
8066
8067 //scdi[15] = litcolour
8068 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8069 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
8070
8071 //sdci[16]=mask
8072
8073 */
8074
8075 3 int32_t srcyoffset = yoffset, srcxoffset = xoffset;
8076 3 int32_t bitmapIndex = sdci[2]/10000;
8077 3 int32_t usr_bitmap_index = sdci[2]-10;
8078 3 byte using_user_bitmap = 0;
8079 //Z_scripterrlog("bitmap index is: %d\n",bitmapIndex);
8080 //Z_scripterrlog("Blit() bitmapIndex is: %d\n", bitmapIndex);
8081 #if LOG_BMPBLIT_LEVEL > 0
8082 Z_scripterrlog("Blit() found a dest bitmap ID of: %d\n",bitmapIndex);
8083 #endif
8084
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if ( bitmapIndex > 10000 )
8085 {
8086 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
8087 }
8088
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if ( usr_bitmap_index > 0 && usr_bitmap_index < 10000 )
8089 {
8090 bitmapIndex = usr_bitmap_index;
8091 using_user_bitmap = 1;
8092 srcyoffset = 0;
8093 }
8094
8095 3 int32_t sx = sdci[3]/10000;
8096 3 int32_t sy = sdci[4]/10000;
8097 3 int32_t sw = sdci[5]/10000;
8098 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
8099 3 int32_t sh = sdci[6]/10000;
8100 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
8101 3 int32_t dx = sdci[7]/10000;
8102 3 int32_t dy = sdci[8]/10000;
8103 3 int32_t dw = sdci[9]/10000;
8104 3 int32_t dh = sdci[10]/10000;
8105 3 float rot = sdci[11]/10000;
8106 3 int32_t cx = sdci[12]/10000;
8107 3 int32_t cy = sdci[13]/10000;
8108 3 int32_t mode = sdci[14]/10000;
8109 3 int32_t litcolour = sdci[15]/10000;
8110 3 bool masked = (sdci[16] != 0);
8111
8112 3 int32_t ref = 0;
8113
8114 //These should go down farther, should they not? -V
8115 //dx = dx + xoffset;
8116 //dy = dy + yoffset;
8117
8118
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
8119
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 if ( (bitmapIndex) != -2 && (bitmapIndex) != -1 ) srcyoffset = 0; //Don't crop.
8120 //Do we need to also check the render target and do the same thing if the
8121 //dest == -2 and the render target is not RT_SCREEN?
8122 3 dx = dx + xoffset;
8123 3 dy = dy + yoffset;
8124 3 sx = sx + srcxoffset;
8125 3 sy = sy + srcyoffset;
8126
8127 3 ref = sdci[17];
8128 //Z_scripterrlog("bitmap->blit() ref id this frame is: %d\n", ref);
8129 3 ref -=10;
8130 //Z_scripterrlog("bitmap->blit() modified ref id this frame is: %d\n", ref);
8131
8132
8133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( ref <= 0 )
8134 {
8135 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
8136 return;
8137 }
8138 3 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
8139 #if LOG_BMPBLIT_LEVEL > 0
8140 Z_scripterrlog("bitmap->Blit() is trying to blit to ref: %d\n",sdci[17]);
8141 #endif
8142
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!sourceBitmap)
8143 {
8144 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
8145 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
8146 return;
8147 }
8148
8149 3 BITMAP *destBMP=NULL;
8150 //zprint2("RevBlit bitmap index is: %d\n",bitmapIndex);
8151
8152
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 switch(bitmapIndex)
8153 {
8154 case -2:
8155 {
8156 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
8157 //zprint2("current RT is: %d\n", curr_rt);
8158 if ( curr_rt >= 0 && curr_rt < 7 )
8159 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
8160 else destBMP = bmp; //screen
8161 break;
8162 }
8163 case -1:
8164 3 destBMP = bmp; //this is framebuf, by default
8165 3 break;
8166 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
8167 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
8168 //destBMP = framebuf; //Drawing to the screen.
8169 //break;
8170
8171 //1 through 6 are the old system bitmaps (Render Targets)
8172 case 0:
8173 case 1:
8174 case 2:
8175 case 3:
8176 case 4:
8177 case 5:
8178 case 6:
8179 {
8180 //This gets a render target.
8181 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
8182
8183 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
8184 //sdci[18] = bitmapIndex;
8185 break;
8186 }
8187 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
8188 default:
8189 {
8190 destBMP = scb.script_created_bitmaps[usr_bitmap_index].u_bmp;
8191 //sdci[18] = usr_bitmap_index;
8192 if ( !scb.script_created_bitmaps[usr_bitmap_index].u_bmp )
8193 {
8194 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
8195 break;
8196 }
8197 }
8198 //FFCore.get_user_bitmap(bitmapIndex); break;
8199 }
8200
8201 #if LOG_BMPBLIT_LEVEL > 0
8202 Z_scripterrlog("bitmap->Blit() is trying to blit to dest bitmap ID: %d\n",bitmapIndex);
8203 #endif
8204
8205
8206
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (!destBMP)
8207 {
8208 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
8209 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
8210 return;
8211 }
8212
8213 //bugfix
8214 //sx = vbound(sx, 0, sourceBitmap->w);
8215 #if LOG_BMPBLIT_LEVEL > 0
8216 Z_scripterrlog("Blit %s is: %d\n", "sx", sx);
8217 Z_scripterrlog("Blit %s is: %d\n", "source->w", sourceBitmap->w);
8218 #endif
8219 //sy = vbound(sy, 0, sourceBitmap->h);
8220 #if LOG_BMPBLIT_LEVEL > 0
8221 Z_scripterrlog("Blit %s is: %d\n", "sy", sy);
8222 Z_scripterrlog("Blit %s is: %d\n", "source->h", sourceBitmap->h);
8223 #endif
8224 //sw = vbound(sw, 0, sourceBitmap->w - sx); //keep the w/h within range as well
8225 #if LOG_BMPBLIT_LEVEL > 0
8226 Z_scripterrlog("Blit %s is: %d\n", "sw", sw);
8227 #endif
8228 //sh = vbound(sh, 0, sourceBitmap->h - sy);
8229 #if LOG_BMPBLIT_LEVEL > 0
8230 Z_scripterrlog("Blit %s is: %d\n", "sh", sh);
8231
8232 Z_scripterrlog("Blit %s is: %d\n", "dx", dx);
8233 Z_scripterrlog("Blit %s is: %d\n", "dy", dy);
8234 Z_scripterrlog("Blit %s is: %d\n", "dh", dh);
8235 Z_scripterrlog("Blit %s is: %d\n", "dw", dw);
8236 Z_scripterrlog("Blit %s is: %d\n", "yoffset", yoffset);
8237 #endif
8238
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 bool stretched = (sw != dw || sh != dh);
8239 //bool stretched = (sourceBitmap->w != destBMP->w || sourceBitmap->h != destBMP->h);
8240 #if LOG_BMPBLIT_LEVEL > 0
8241 Z_scripterrlog("Blit %s is: %s\n", "stretched", stretched ? "true" : "false");
8242 #endif
8243 //BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
8244
8245
8246
8247 3 BITMAP* newDest = sourceBitmap;
8248 3 BITMAP* newSource = destBMP; //Flip them.
8249
8250 3 BITMAP* subBmp = 0;
8251
8252 /* IDR what this was. -Z ( 17th April, 2019 )
8253 if ( bitmapIndex == -1 ) {
8254 blit(bmp, sourceBitmap, sx, sy, 0, 0, dw, dh);
8255 }
8256 */
8257
8258
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if(rot != 0 || mode != 0)
8259 {
8260 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
8261 clear_bitmap(subBmp);
8262
8263 if(!subBmp)
8264 {
8265 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
8266 return;
8267 }
8268 }
8269
8270
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 if (sx + sw > destBMP->w || sy + sh > destBMP->h)
8271 {
8272 3 newSource = create_bitmap_ex(8, sw, sh);
8273 3 clear_bitmap(newSource);
8274 3 blit(destBMP, newSource, sx, sy, 0, 0, std::min(destBMP->w-sx, sw), std::min(destBMP->h-sy, sh));
8275 3 sx = 0;
8276 3 sy = 0;
8277 3 }
8278 //dx = dx + xoffset; //don't do this here!
8279 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
8280
8281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(stretched)
8282 {
8283 if(masked)
8284 { //stretched and masked
8285 if ( rot == 0 )
8286 { //if not rotated
8287 switch(mode)
8288 {
8289 case 1:
8290 //transparent
8291 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8292 draw_trans_sprite(newDest, subBmp, dx, dy);
8293 break;
8294
8295
8296 case 2:
8297 //pivot?
8298 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8299 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8300 //Pivoting requires two more args
8301 break;
8302
8303 case 3:
8304 //pivot + trans
8305 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8306 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8307 break;
8308
8309 case 4:
8310 //flip v
8311 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8312 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8313 break;
8314
8315 case 5:
8316 //trans + v flip
8317 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8318 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8319 break;
8320
8321 case 6:
8322 //pivot + v flip
8323 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8324 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8325 break;
8326
8327 case 8:
8328 //vlip h
8329 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8330 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8331 break;
8332
8333 case 9:
8334 //trans + h flip
8335 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8336 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8337 break;
8338
8339 case 10:
8340 //flip H and pivot
8341 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8342 //return error cannot pivot and h flip
8343 break;
8344
8345 case 12:
8346 //vh flip
8347 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8348 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8349 break;
8350
8351 case 13:
8352 //trans + vh flip
8353 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8354 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8355 break;
8356
8357 case 14:
8358 //pivot and vh flip
8359 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8360 //return error cannot both pivot and vh flip
8361 break;
8362
8363 case 16:
8364 //lit
8365 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8366 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8367 break;
8368
8369 case 18:
8370 //pivot, lit
8371 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8372 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8373 break;
8374
8375 case 20:
8376 //lit + v flip
8377 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8378 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8379 break;
8380
8381 case 22:
8382 //Pivot, vflip, lit
8383 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8384 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8385 break;
8386
8387 case 24:
8388 //lit + h flip
8389 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8390 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8391 break;
8392
8393 case 26:
8394 //pivot + lit + hflip
8395 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8396 //return error cannot pivot, lit, and flip
8397 break;
8398
8399 case 28:
8400 //lit + vh flip
8401 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8402 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8403 break;
8404
8405 case 32: //gouraud
8406 //Probably not wort supporting.
8407 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8408 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8409 break;
8410
8411 case 0:
8412 //no effect
8413 masked_stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8414 break;
8415
8416
8417 default:
8418 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8419
8420
8421 }
8422 } //end if not rotated
8423
8424 if ( rot != 0 ) //if rotated
8425 {
8426 switch(mode)
8427 {
8428 case 1:
8429 //transparent
8430 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8431 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8432
8433 break;
8434
8435 case 2:
8436 //pivot?
8437 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8438 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8439 //Pivoting requires two more args
8440 break;
8441
8442 case 3:
8443 //pivot + trans
8444 //return an error, cannot both rotate and pivot
8445 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8446 break;
8447
8448 case 4:
8449 //flip v
8450 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8451 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8452 break;
8453
8454 case 5:
8455 //trans + v flip
8456 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8457 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8458 break;
8459
8460 case 6:
8461 //pivot + v flip
8462 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8463 //return an error, cannot both rotate and pivot
8464 break;
8465
8466 case 8:
8467 //flip h
8468 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8469 //return an error, cannot both rotate and flip H
8470 break;
8471
8472 case 9:
8473 //trans + h flip
8474 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8475 //return an error, cannot rotate and flip a trans sprite
8476 break;
8477
8478 case 10:
8479 //flip H and pivot
8480 //return error cannot pivot and h flip
8481 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8482 break;
8483
8484 case 12:
8485 //vh flip
8486 //return an error, cannot rotate and VH flip a trans sprite
8487 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8488 break;
8489
8490 case 13:
8491 //trans + vh flip
8492 //return an error, cannot rotate and VH flip a trans sprite
8493 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8494 break;
8495
8496 case 14:
8497 //pivot and vh flip
8498 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8499 //return error cannot both pivot and vh flip
8500 break;
8501
8502 case 16:
8503 //lit
8504 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8505 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8506 break;
8507
8508 case 18:
8509 //pivot, lit
8510 //return an error, cannot both rotate and pivot
8511 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8512 break;
8513
8514 case 20:
8515 //lit + vflip
8516 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8517 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8518 break;
8519
8520 case 22:
8521 //Pivot, vflip, lit
8522 //return an error, cannot both rotate and pivot
8523 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8524 break;
8525
8526 case 24:
8527 //lit + h flip
8528 //return an error, cannot both rotate and H flip
8529 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8530 break;
8531
8532 case 26:
8533 //pivot + lit + hflip
8534 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8535 //return error cannot pivot, lit, and flip
8536 break;
8537
8538 case 28:
8539 //lit + vh flip
8540 //return an error, cannot both rotate and VH flip
8541 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8542 break;
8543
8544 case 32: //gouraud
8545 //Probably not wort supporting.
8546 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8547 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8548 break;
8549
8550 case 0:
8551 //no effect.
8552 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8553 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8554 break;
8555
8556 default:
8557 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8558
8559 }
8560 }
8561 } //end if stretched and masked
8562
8563 else //stretched, not masked
8564 {
8565
8566
8567 if ( rot == 0 ) //if not rotated
8568 {
8569 switch(mode)
8570 {
8571 case 1:
8572 //transparent
8573 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8574 draw_trans_sprite(newDest, subBmp, dx, dy);
8575 break;
8576
8577
8578 case 2:
8579 //pivot?
8580 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8581 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8582 //Pivoting requires two more args
8583 break;
8584
8585 case 3:
8586 //pivot + trans
8587 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8588 pivot_sprite_trans(newDest, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
8589 break;
8590
8591 case 4:
8592 //flip v
8593 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8594 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8595 break;
8596
8597 case 5:
8598 //trans + v flip
8599 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8600 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8601 break;
8602
8603 case 6:
8604 //pivot + v flip
8605 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8606 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8607 break;
8608
8609 case 8:
8610 //vlip h
8611 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8612 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8613 break;
8614
8615 case 9:
8616 //trans + h flip
8617 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8618 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8619 break;
8620
8621 case 10:
8622 //flip H and pivot
8623 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8624 //return error cannot pivot and h flip
8625 break;
8626
8627 case 12:
8628 //vh flip
8629 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8630 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8631 break;
8632
8633 case 13:
8634 //trans + vh flip
8635 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8636 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8637 break;
8638
8639 case 14:
8640 //pivot and vh flip
8641 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8642 //return error cannot both pivot and vh flip
8643 break;
8644
8645 case 16:
8646 //lit
8647 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8648 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8649 break;
8650
8651 case 18:
8652 //pivot, lit
8653 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8654 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8655 break;
8656
8657 case 20:
8658 //lit + v flip
8659 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8660 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8661 break;
8662
8663 case 22:
8664 //Pivot, vflip, lit
8665 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8666 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8667 break;
8668
8669 case 24:
8670 //lit + h flip
8671 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8672 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8673 break;
8674
8675 case 26:
8676 //pivot + lit + hflip
8677 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8678 //return error cannot pivot, lit, and flip
8679 break;
8680
8681 case 28:
8682 //lit + vh flip
8683 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8684 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8685 break;
8686
8687 case 32: //gouraud
8688 //Probably not wort supporting.
8689 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8690 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8691 break;
8692
8693 case 0:
8694 //no effect
8695 stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8696 break;
8697
8698
8699 default:
8700 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8701
8702
8703 }
8704 } //end if not rotated
8705
8706 if ( rot != 0 ) //if rotated
8707 {
8708 switch(mode)
8709 {
8710 case 1:
8711 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8712 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8713
8714 break;
8715
8716 case 2:
8717 //pivot?
8718 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8719 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8720 //Pivoting requires two more args
8721 break;
8722
8723 case 3:
8724 //pivot + trans
8725 //return an error, cannot both rotate and pivot
8726 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8727 break;
8728
8729 case 4:
8730 //flip v
8731 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8732 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8733 break;
8734
8735 case 5:
8736 //trans + v flip
8737 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8738 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8739 break;
8740
8741 case 6:
8742 //pivot + v flip
8743 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8744 //return an error, cannot both rotate and pivot
8745 break;
8746
8747 case 8:
8748 //flip h
8749 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8750 //return an error, cannot both rotate and flip H
8751 break;
8752
8753 case 9:
8754 //trans + h flip
8755 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8756 //return an error, cannot rotate and flip a trans sprite
8757 break;
8758
8759 case 10:
8760 //flip H and pivot
8761 //return error cannot pivot and h flip
8762 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8763 break;
8764
8765 case 12:
8766 //vh flip
8767 //return an error, cannot rotate and VH flip a trans sprite
8768 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8769 break;
8770
8771 case 13:
8772 //trans + vh flip
8773 //return an error, cannot rotate and VH flip a trans sprite
8774 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8775 break;
8776
8777 case 14:
8778 //pivot and vh flip
8779 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8780 //return error cannot both pivot and vh flip
8781 break;
8782
8783 case 16:
8784 //lit
8785 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8786 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8787 break;
8788
8789 case 18:
8790 //pivot, lit
8791 //return an error, cannot both rotate and pivot
8792 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8793 break;
8794
8795 case 20:
8796 //lit + vflip
8797 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8798 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8799 break;
8800
8801 case 22:
8802 //Pivot, vflip, lit
8803 //return an error, cannot both rotate and pivot
8804 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8805 break;
8806
8807 case 24:
8808 //lit + h flip
8809 //return an error, cannot both rotate and H flip
8810 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8811 break;
8812
8813 case 26:
8814 //pivot + lit + hflip
8815 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8816 //return error cannot pivot, lit, and flip
8817 break;
8818
8819 case 28:
8820 //lit + vh flip
8821 //return an error, cannot both rotate and VH flip
8822 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8823 break;
8824
8825 case 32: //gouraud
8826 //Probably not wort supporting.
8827 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8828 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8829 break;
8830
8831 case 0:
8832 //no effect.
8833 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8834 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8835 break;
8836
8837 default:
8838 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8839
8840 }
8841 }
8842
8843 } //end if stretched, but not masked
8844 }
8845 else //not stretched
8846 {
8847
8848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(masked) //if masked, but not stretched
8849 {
8850
8851 if ( rot == 0 ) //if not rotated
8852 {
8853 switch(mode)
8854 {
8855 case 1:
8856 //transparent
8857 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8858 draw_trans_sprite(newDest, subBmp, dx, dy);
8859 break;
8860
8861
8862 case 2:
8863 //pivot?
8864 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8865 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8866 //Pivoting requires two more args
8867 break;
8868
8869 case 3:
8870 //pivot + trans
8871 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8872 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8873 break;
8874
8875 case 4:
8876 //flip v
8877 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8878 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8879 break;
8880
8881 case 5:
8882 //trans + v flip
8883 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8884 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8885 break;
8886
8887 case 6:
8888 //pivot + v flip
8889 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8890 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8891 break;
8892
8893 case 8:
8894 //vlip h
8895 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8896 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8897 break;
8898
8899 case 9:
8900 //trans + h flip
8901 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8902 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8903 break;
8904
8905 case 10:
8906 //flip H and pivot
8907 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8908 //return error cannot pivot and h flip
8909 break;
8910
8911 case 12:
8912 //vh flip
8913 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8914 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8915 break;
8916
8917 case 13:
8918 //trans + vh flip
8919 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8920 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8921 break;
8922
8923 case 14:
8924 //pivot and vh flip
8925 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8926 //return error cannot both pivot and vh flip
8927 break;
8928
8929 case 16:
8930 //lit
8931 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8932 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8933 break;
8934
8935 case 18:
8936 //pivot, lit
8937 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8938 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8939 break;
8940
8941 case 20:
8942 //lit + v flip
8943 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8944 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8945 break;
8946
8947 case 22:
8948 //Pivot, vflip, lit
8949 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8950 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8951 break;
8952
8953 case 24:
8954 //lit + h flip
8955 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8956 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8957 break;
8958
8959 case 26:
8960 //pivot + lit + hflip
8961 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8962 //return error cannot pivot, lit, and flip
8963 break;
8964
8965 case 28:
8966 //lit + vh flip
8967 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8968 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8969 break;
8970
8971 case 32: //gouraud
8972 //Probably not wort supporting.
8973 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8974 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8975 break;
8976
8977 case 0:
8978 //no effect
8979 masked_blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
8980 break;
8981
8982
8983 default:
8984 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8985
8986
8987 }
8988 } //end if not rotated
8989
8990 if ( rot != 0 ) //if rotated
8991 {
8992 switch(mode)
8993 {
8994 case 1:
8995 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //transparent
8996 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8997
8998 break;
8999
9000 case 2:
9001 //pivot?
9002 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9003 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9004 //Pivoting requires two more args
9005 break;
9006
9007 case 3:
9008 //pivot + trans
9009 //return an error, cannot both rotate and pivot
9010 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9011 break;
9012
9013 case 4:
9014 //flip v
9015 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9016 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9017 break;
9018
9019 case 5:
9020 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
9021 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9022 break;
9023
9024 case 6:
9025 //pivot + v flip
9026 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9027 //return an error, cannot both rotate and pivot
9028 break;
9029
9030 case 8:
9031 //flip h
9032 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
9033 //return an error, cannot both rotate and flip H
9034 break;
9035
9036 case 9:
9037 //trans + h flip
9038 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
9039 //return an error, cannot rotate and flip a trans sprite
9040 break;
9041
9042 case 10:
9043 //flip H and pivot
9044 //return error cannot pivot and h flip
9045 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
9046 break;
9047
9048 case 12:
9049 //vh flip
9050 //return an error, cannot rotate and VH flip a trans sprite
9051 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9052 break;
9053
9054 case 13:
9055 //trans + vh flip
9056 //return an error, cannot rotate and VH flip a trans sprite
9057 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9058 break;
9059
9060 case 14:
9061 //pivot and vh flip
9062 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9063 //return error cannot both pivot and vh flip
9064 break;
9065
9066 case 16:
9067 //lit
9068 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9069 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9070 break;
9071
9072 case 18:
9073 //pivot, lit
9074 //return an error, cannot both rotate and pivot
9075 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9076 break;
9077
9078 case 20:
9079 //lit + vflip
9080 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9081 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9082 break;
9083
9084 case 22:
9085 //Pivot, vflip, lit
9086 //return an error, cannot both rotate and pivot
9087 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9088 break;
9089
9090 case 24:
9091 //lit + h flip
9092 //return an error, cannot both rotate and H flip
9093 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
9094 break;
9095
9096 case 26:
9097 //pivot + lit + hflip
9098 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
9099 //return error cannot pivot, lit, and flip
9100 break;
9101
9102 case 28:
9103 //lit + vh flip
9104 //return an error, cannot both rotate and VH flip
9105 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
9106 break;
9107
9108 case 32: //gouraud
9109 //Probably not wort supporting.
9110 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9111 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9112 break;
9113
9114 case 0:
9115 //no effect.
9116 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9117 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9118 break;
9119
9120 default:
9121 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
9122
9123 }
9124 } //end rtated, masked
9125 } //end if masked
9126
9127 else //not masked, and not stretched; just blit
9128 {
9129
9130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( rot == 0 ) //if not rotated
9131 {
9132
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 3 times.
3 switch(mode)
9133 {
9134 case 1:
9135 //transparent
9136 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9137 draw_trans_sprite(newDest, subBmp, dx, dy);
9138 break;
9139
9140
9141 case 2:
9142 //pivot?
9143 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9144 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9145 //Pivoting requires two more args
9146 break;
9147
9148 case 3:
9149 //pivot + trans
9150 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9151 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9152 break;
9153
9154 case 4:
9155 //flip v
9156 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9157 draw_sprite_v_flip(newDest, subBmp, dx, dy);
9158 break;
9159
9160 case 5:
9161 //trans + v flip
9162 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9163 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9164 break;
9165
9166 case 6:
9167 //pivot + v flip
9168 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9169 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9170 break;
9171
9172 case 8:
9173 //vlip h
9174 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9175 draw_sprite_h_flip(newDest, subBmp, dx, dy);
9176 break;
9177
9178 case 9:
9179 //trans + h flip
9180 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9181 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9182 break;
9183
9184 case 10:
9185 //flip H and pivot
9186 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
9187 //return error cannot pivot and h flip
9188 break;
9189
9190 case 12:
9191 //vh flip
9192 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9193 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
9194 break;
9195
9196 case 13:
9197 //trans + vh flip
9198 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9199 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9200 break;
9201
9202 case 14:
9203 //pivot and vh flip
9204 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
9205 //return error cannot both pivot and vh flip
9206 break;
9207
9208 case 16:
9209 //lit
9210 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9211 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
9212 break;
9213
9214 case 18:
9215 //pivot, lit
9216 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9217 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9218 break;
9219
9220 case 20:
9221 //lit + v flip
9222 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9223 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9224 break;
9225
9226 case 22:
9227 //Pivot, vflip, lit
9228 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9229 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9230 break;
9231
9232 case 24:
9233 //lit + h flip
9234 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9235 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9236 break;
9237
9238 case 26:
9239 //pivot + lit + hflip
9240 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
9241 //return error cannot pivot, lit, and flip
9242 break;
9243
9244 case 28:
9245 //lit + vh flip
9246 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9247 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9248 break;
9249
9250 case 32: //gouraud
9251 //Probably not wort supporting.
9252 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9253 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9254 break;
9255
9256 case 0:
9257 //no effect
9258 3 blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
9259 3 break;
9260
9261
9262 default:
9263 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
9264
9265
9266 }
9267 3 } //end if not rotated
9268
9269
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if ( rot != 0 ) //if rotated
9270 {
9271 switch(mode)
9272 {
9273 case 1:
9274 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);//transparent
9275 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9276
9277 break;
9278
9279 case 2:
9280 //pivot?
9281 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9282 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9283 //Pivoting requires two more args
9284 break;
9285
9286 case 3:
9287 //pivot + trans
9288 //return an error, cannot both rotate and pivot
9289 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9290 break;
9291
9292 case 4:
9293 //flip v
9294 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9295 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9296 break;
9297
9298 case 5:
9299 //trans + v flip
9300 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9301 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9302 break;
9303
9304 case 6:
9305 //pivot + v flip
9306 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9307 //return an error, cannot both rotate and pivot
9308 break;
9309
9310 case 8:
9311 //flip h
9312 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
9313 //return an error, cannot both rotate and flip H
9314 break;
9315
9316 case 9:
9317 //trans + h flip
9318 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
9319 //return an error, cannot rotate and flip a trans sprite
9320 break;
9321
9322 case 10:
9323 //flip H and pivot
9324 //return error cannot pivot and h flip
9325 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
9326 break;
9327
9328 case 12:
9329 //vh flip
9330 //return an error, cannot rotate and VH flip a trans sprite
9331 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9332 break;
9333
9334 case 13:
9335 //trans + vh flip
9336 //return an error, cannot rotate and VH flip a trans sprite
9337 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9338 break;
9339
9340 case 14:
9341 //pivot and vh flip
9342 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9343 //return error cannot both pivot and vh flip
9344 break;
9345
9346 case 16:
9347 //lit
9348 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9349 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9350 break;
9351
9352 case 18:
9353 //pivot, lit
9354 //return an error, cannot both rotate and pivot
9355 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9356 break;
9357
9358 case 20:
9359 //lit + vflip
9360 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9361 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9362 break;
9363
9364 case 22:
9365 //Pivot, vflip, lit
9366 //return an error, cannot both rotate and pivot
9367 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9368 break;
9369
9370 case 24:
9371 //lit + h flip
9372 //return an error, cannot both rotate and H flip
9373 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
9374 break;
9375
9376 case 26:
9377 //pivot + lit + hflip
9378 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
9379 //return error cannot pivot, lit, and flip
9380 break;
9381
9382 case 28:
9383 //lit + vh flip
9384 //return an error, cannot both rotate and VH flip
9385 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
9386 break;
9387
9388 case 32: //gouraud
9389 //Probably not wort supporting.
9390 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9391 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9392 break;
9393
9394 case 0:
9395 //no effect.
9396 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9397 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9398 break;
9399
9400 default:
9401 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
9402
9403 }
9404 } //end if rotated
9405 } //end if not masked
9406 } //end if not stretched
9407
9408 //cleanup
9409
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(subBmp)
9410 {
9411 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
9412 destroy_bitmap(subBmp);
9413 }
9414
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(newSource != destBMP)
9415 {
9416 3 destroy_bitmap(newSource);
9417 3 }
9418 3 }
9419
9420
9421 void bmp_do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
9422 {
9423
9424 //sdci[1]=layer
9425 //sdci[2]=pos[12]
9426 //sdci[3]=uv[8]
9427 //sdci[4]=color[4]
9428 //sdci[5]=size[2]
9429 //sdci[6]=flip
9430 //sdci[7]=tile/combo
9431 //sdci[8]=polytype
9432 //sdci[9] = other bitmap as texture
9433 //sdci[17] Bitmap Pointer
9434 if ( sdci[17] <= 0 )
9435 {
9436 Z_scripterrlog("bitmap->Quad3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
9437 return;
9438 }
9439 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
9440 if ( refbmp == NULL ) return;
9441
9442 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
9443
9444 if(!v_ptr)
9445 {
9446 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
9447 return;
9448 }
9449
9450 std::vector<int32_t> &v = *v_ptr;
9451
9452 if(v.empty())
9453 return;
9454
9455 int32_t* pos = &v[0];
9456 int32_t* uv = &v[12];
9457 int32_t* col = &v[20];
9458 int32_t* size = &v[24];
9459
9460 int32_t w = size[0]; //magic numerical constants... yuck.
9461 int32_t h = size[1];
9462 int32_t flip = (sdci[6]/10000)&3;
9463 int32_t tile = sdci[7]/10000;
9464 int32_t polytype = sdci[8]/10000;
9465 int32_t quad_render_source = sdci[9]-10;
9466 Z_scripterrlog("Quad3D texture is %d\n", quad_render_source);
9467
9468 polytype = vbound(polytype, 0, 14);
9469
9470 int32_t tex_width = w*16;
9471 int32_t tex_height = h*16;
9472
9473 bool mustDestroyBmp = false;
9474 BITMAP *tex=NULL;
9475
9476
9477 bool tex_is_bitmap = ( sdci[9] != 0 );
9478 //Z_scripterrlog("sdci[9] is %d\n", quad_render_source);
9479 //Z_scripterrlog("sdci[17] is %d\n", sdci[17]-10);
9480 BITMAP *bmptexture;
9481
9482 if ( tex_is_bitmap ) bmptexture = FFCore.GetScriptBitmap(quad_render_source);
9483
9484 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9485
9486
9487 if ( !tex_is_bitmap )
9488 {
9489 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
9490
9491 if(!tex)
9492 {
9493 mustDestroyBmp = true;
9494 tex = create_bitmap_ex(8, tex_width, tex_height);
9495 clear_bitmap(tex);
9496 }
9497 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
9498 {
9499 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
9500 return; //non power of two error
9501 }
9502 if(tile > 0) // TILE
9503 {
9504 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
9505 }
9506 else // COMBO
9507 {
9508 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
9509 const int32_t tiletodraw = combo_tile(c, 0, 0);
9510 flip = flip ^ c.flip;
9511
9512 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
9513 }
9514
9515 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
9516 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
9517 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
9518 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
9519
9520 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
9521 if(mustDestroyBmp)
9522 destroy_bitmap(tex);
9523 }
9524 else
9525 {
9526
9527 if ( !bmptexture )
9528 {
9529 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Quad3D()");
9530 tex_is_bitmap = 0;
9531 return;
9532 }
9533 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
9534 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
9535 if ( !isPowerOfTwo(h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
9536 if ( !isPowerOfTwo(w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
9537
9538 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
9539 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
9540 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
9541 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
9542
9543 BITMAP *foo = create_bitmap_ex(8, 256, 176);
9544
9545 //quad3d_f(refbmp, polytype, foo, &V1, &V2, &V3, &V4);
9546 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
9547 destroy_bitmap(foo);
9548
9549 }
9550
9551
9552
9553 }
9554
9555
9556
9557 void bmp_do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
9558 {
9559 //sdci[1]=layer
9560 //sdci[2]=pos[9]
9561 //sdci[3]=uv[6]
9562 //sdci[4]=color[3]
9563 //sdci[5]=size[2]
9564 //sdci[6]=flip
9565 //sdci[7]=tile/combo
9566 //sdci[8]=polytype
9567 //sdci[9] bitmap as texture
9568 //sdci[17] Bitmap Pointer
9569 if ( sdci[17] <= 0 )
9570 {
9571 Z_scripterrlog("bitmap->Triangle3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
9572 return;
9573 }
9574 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
9575 if ( refbmp == NULL ) return;
9576
9577 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
9578
9579 if(!v_ptr)
9580 {
9581 al_trace("bitmap->Triangle3d: Vector pointer is null! Internal error. \n");
9582 return;
9583 }
9584
9585 std::vector<int32_t> &v = *v_ptr;
9586
9587 if(v.empty())
9588 return;
9589
9590 int32_t* pos = &v[0];
9591 int32_t* uv = &v[9];
9592 int32_t* col = &v[15];
9593 int32_t* size = &v[18];
9594
9595 int32_t w = size[0]; //magic numerical constants... yuck.
9596 int32_t h = size[1];
9597 int32_t flip = (sdci[6]/10000)&3;
9598 int32_t tile = sdci[7]/10000;
9599 int32_t polytype = sdci[8]/10000;
9600 int32_t quad_render_source = sdci[9]-10;
9601 polytype = vbound(polytype, 0, 14);
9602
9603 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
9604 {
9605 Z_message("bitmap->Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
9606 return; //non power of two error
9607 }
9608
9609 int32_t tex_width = w*16;
9610 int32_t tex_height = h*16;
9611
9612 bool mustDestroyBmp = false;
9613 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
9614
9615 if(!tex)
9616 {
9617 mustDestroyBmp = true;
9618 tex = create_bitmap_ex(8, tex_width, tex_height);
9619 clear_bitmap(tex);
9620 }
9621
9622 bool tex_is_bitmap = ( sdci[9] != 0 );
9623 BITMAP *bmptexture=NULL;
9624 if ( tex_is_bitmap )
9625 {
9626 bmptexture = FFCore.GetScriptBitmap(quad_render_source);
9627 if ( !bmptexture )
9628 {
9629 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
9630 tex_is_bitmap = 0;
9631 }
9632 }
9633
9634 if ( !tex_is_bitmap )
9635 {
9636 if(tile > 0) // TILE
9637 {
9638 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
9639 }
9640 else // COMBO
9641 {
9642 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
9643 const int32_t tiletodraw = combo_tile(c, 0, 0);
9644 flip = flip ^ c.flip;
9645
9646 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
9647 }
9648
9649 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
9650 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
9651 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
9652
9653 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
9654 }
9655 else
9656 {
9657 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
9658 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
9659 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
9660 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
9661
9662 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
9663 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
9664 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
9665
9666 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
9667
9668
9669 }
9670 if(mustDestroyBmp)
9671 destroy_bitmap(tex);
9672
9673 }
9674
9675
9676 bool is_layer_transparent(const mapscr& m, int32_t layer)
9677 {
9678 layer = vbound(layer, 0, 5);
9679 return m.layeropacity[layer] == 128;
9680 }
9681
9682 21 mapscr *getmapscreen(int32_t map_index, int32_t screen_index, int32_t layer) //returns NULL for invalid or non-existent layer
9683 {
9684 mapscr *base_screen;
9685 21 int32_t index = map_index*MAPSCRS+screen_index;
9686
9687
2/4
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
21 if((uint32_t)layer > 6 || (uint32_t)index >= TheMaps.size())
9688 return NULL;
9689
9690
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 18 times.
21 if(layer != 0)
9691 {
9692 18 layer = layer - 1;
9693
9694 18 base_screen=&(TheMaps[index]);
9695
9696
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 if(base_screen->layermap[layer]==0)
9697 6 return NULL;
9698
9699 12 index=(base_screen->layermap[layer]-1)*MAPSCRS+base_screen->layerscreen[layer];
9700
9701
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if((uint32_t)index >= TheMaps.size()) // Might as well make sure
9702 return NULL;
9703 12 }
9704
9705 15 return &(TheMaps[index]);
9706 21 }
9707
9708 138 void draw_mapscr(BITMAP *b, const mapscr& m, int32_t x, int32_t y, bool transparent)
9709 {
9710
2/2
✓ Branch 0 taken 24288 times.
✓ Branch 1 taken 138 times.
24426 for(int32_t i(0); i < 176; ++i)
9711 {
9712 24288 const int32_t x2 = ((i&15)<<4) + x;
9713 24288 const int32_t y2 = (i&0xF0) + y;
9714
9715 //const newcombo & c = combobuf[ m.data[i] ];
9716 /*
9717 newcombo c = combobuf[m.data[i]];
9718 int32_t csets[4];
9719 int32_t cofs = c.csets&15;
9720
9721 if(cofs&8)
9722 cofs |= ~int32_t(0xF);
9723
9724 for(int32_t i=0; i<4; ++i)
9725 csets[i] = c.csets&(16<<i) ? cset + cofs : cset;
9726
9727
9728 const int32_t tile = combo_tile(c, x2, y2);
9729 */
9730
9731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24288 times.
24288 if(transparent)
9732 {
9733 //void overcomboblocktranslucent(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h, int32_t opacity)
9734 overcomboblocktranslucent(b, x2, y2, m.data[i], m.cset[i], 1, 1, 128);
9735 //overtiletranslucent16(b, tile, x2, y2, m.cset[i], c.flip, 128);
9736 }
9737 else
9738 {
9739 //overcomboblock(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h)
9740 24288 overcomboblock(b, x2, y2, m.data[i], m.cset[i], 1, 1);
9741 //overtile16(b, tile, x2, y2, m.cset[i], c.flip);
9742 }
9743 24288 }
9744 138 }
9745
9746 void draw_map_solidity(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
9747 {
9748 BITMAP* square = create_bitmap_ex(8,16,16);
9749
9750 for(int32_t i(0); i < 176; ++i)
9751 {
9752 const int32_t x2 = ((i&15)<<4) + x;
9753 const int32_t y2 = (i&0xF0) + y;
9754 //Blit the palette index of the solidity value.
9755 //int32_t col = (combobuf[m.data[i]].walk&15);
9756 //if ( col != 0 )
9757 //{
9758 // Z_scripterrlog("Position %d has a solidity value of %d.\n", i, col);
9759 //
9760 //}
9761 clear_to_color(square,(combobuf[m.data[i]].walk&15));
9762 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
9763 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
9764 }
9765 destroy_bitmap(square);
9766 }
9767
9768 void do_bmpdrawscreen_solidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9769 {
9770 //sdci[1]=layer
9771 //sdci[2]=map
9772 //sdci[3]=screen
9773 //sdci[4]=x
9774 //sdci[5]=y
9775 //sdci[6]=rotation
9776 //sdci[17] Bitmap Pointer
9777
9778 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
9779 if ( refbmp == NULL ) return;
9780
9781 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9782
9783 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9784 int32_t scrn = sdci[3]/10000;
9785 int32_t x = sdci[4]/10000;
9786 int32_t y = sdci[5]/10000;
9787 int32_t x1 = x + xoffset;
9788 int32_t y1 = y + yoffset;
9789 int32_t rotation = sdci[6]/10000;
9790
9791 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9792
9793 if(index >= TheMaps.size())
9794 {
9795 al_trace("DrawScreen: invalid map or screen index. \n");
9796 return;
9797 }
9798
9799 const mapscr & m = TheMaps[index];
9800
9801
9802 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
9803 if ( refbmp == NULL ) return;
9804
9805 if(rotation != 0)
9806 b = script_drawing_commands.AquireSubBitmap(256, 176);
9807
9808 //draw layer 0
9809 draw_map_solidity(b, m, x1, y1);
9810 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS))
9811 {
9812 for(int32_t i(0); i < 6; ++i)
9813 {
9814 if(m.layermap[i] == 0) continue;
9815
9816 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
9817
9818 if(layer_screen_index >= TheMaps.size())
9819 continue;
9820
9821 //draw valid layers
9822 draw_map_solidity(b, TheMaps[ layer_screen_index ], x1, y1);
9823 }
9824 }
9825
9826 if(rotation != 0) // rotate
9827 {
9828 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
9829 script_drawing_commands.ReleaseSubBitmap(b);
9830 }
9831 }
9832
9833 void draw_map_solid(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
9834 {
9835 BITMAP* square = create_bitmap_ex(8,16,16);
9836 BITMAP* subsquare = create_bitmap_ex(8,16,16);
9837 clear_to_color(subsquare,1);
9838
9839 for(int32_t i(0); i < 176; ++i)
9840 {
9841 const int32_t x2 = ((i&15)<<4) + x;
9842 const int32_t y2 = (i&0xF0) + y;
9843 //Blit the palette index of the solidity value.
9844 //int32_t col = (combobuf[m.data[i]].walk&15);
9845 //if ( col != 0 )
9846 //{
9847 // Z_scripterrlog("Position %d has a solidity value of %d.\n", i, col);
9848 //
9849 //}
9850 clear_bitmap(square);
9851 int32_t sol = (combobuf[m.data[i]].walk);
9852 //al_trace("Solidity is: %d.\n", sol);
9853 if ( sol & 1 )
9854 {
9855 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
9856 }
9857 if ( sol & 2 )
9858 {
9859 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
9860 }
9861 if ( sol & 4 )
9862 {
9863 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
9864 }
9865 if ( sol &8 ) {
9866 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
9867 }
9868
9869 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
9870 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
9871 }
9872 destroy_bitmap(square);
9873 destroy_bitmap(subsquare);
9874 }
9875
9876 void do_bmpdrawscreen_solidr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9877 {
9878 //sdci[1]=layer
9879 //sdci[2]=map
9880 //sdci[3]=screen
9881 //sdci[4]=x
9882 //sdci[5]=y
9883 //sdci[6]=rotation
9884 //sdci[17] Bitmap Pointer
9885
9886 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
9887 if ( refbmp == NULL ) return;
9888
9889 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9890
9891 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9892 int32_t scrn = sdci[3]/10000;
9893 int32_t x = sdci[4]/10000;
9894 int32_t y = sdci[5]/10000;
9895 int32_t x1 = x + xoffset;
9896 int32_t y1 = y + yoffset;
9897 int32_t rotation = sdci[6]/10000;
9898
9899 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9900
9901 if(index >= TheMaps.size())
9902 {
9903 al_trace("DrawScreen: invalid map or screen index. \n");
9904 return;
9905 }
9906
9907 const mapscr & m = TheMaps[index];
9908
9909
9910 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
9911 if ( refbmp == NULL ) return;
9912
9913 if(rotation != 0)
9914 b = script_drawing_commands.AquireSubBitmap(256, 176);
9915
9916 //draw layer 0
9917 draw_map_solid(b, m, x1, y1);
9918
9919 for(int32_t i(0); i < 6; ++i) //This one doesn't need the QR; it works just fine.
9920 {
9921 if(m.layermap[i] == 0) continue;
9922
9923 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
9924
9925 if(layer_screen_index >= TheMaps.size())
9926 continue;
9927
9928 //draw valid layers
9929 draw_map_solid(b, TheMaps[ layer_screen_index ], x1, y1);
9930 }
9931
9932 if(rotation != 0) // rotate
9933 {
9934 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
9935 script_drawing_commands.ReleaseSubBitmap(b);
9936 }
9937 }
9938
9939 void draw_map_cflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
9940 {
9941 BITMAP* square = create_bitmap_ex(8,16,16);
9942
9943 for(int32_t i(0); i < 176; ++i)
9944 {
9945 const int32_t x2 = ((i&15)<<4) + x;
9946 const int32_t y2 = (i&0xF0) + y;
9947 //Blit the palette index of the solidity value.
9948 clear_to_color(square,m.sflag[i]);
9949 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
9950 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
9951 }
9952 destroy_bitmap(square);
9953 }
9954
9955 void do_bmpdrawscreen_cflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9956 {
9957 //sdci[1]=layer
9958 //sdci[2]=map
9959 //sdci[3]=screen
9960 //sdci[4]=x
9961 //sdci[5]=y
9962 //sdci[6]=rotation
9963 //sdci[17] Bitmap Pointer
9964
9965 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
9966 if ( refbmp == NULL ) return;
9967
9968 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9969
9970 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9971 int32_t scrn = sdci[3]/10000;
9972 int32_t x = sdci[4]/10000;
9973 int32_t y = sdci[5]/10000;
9974 int32_t x1 = x + xoffset;
9975 int32_t y1 = y + yoffset;
9976 int32_t rotation = sdci[6]/10000;
9977
9978 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9979
9980 if(index >= TheMaps.size())
9981 {
9982 al_trace("DrawScreen: invalid map or screen index. \n");
9983 return;
9984 }
9985
9986 const mapscr & m = TheMaps[index];
9987
9988
9989 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
9990 if ( refbmp == NULL ) return;
9991
9992 if(rotation != 0)
9993 b = script_drawing_commands.AquireSubBitmap(256, 176);
9994
9995 //draw layer 0
9996 draw_map_cflag(b, m, x1, y1);
9997 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS))
9998 {
9999 for(int32_t i(0); i < 6; ++i)
10000 {
10001 if(m.layermap[i] == 0) continue;
10002
10003 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10004
10005 if(layer_screen_index >= TheMaps.size())
10006 continue;
10007
10008 //draw valid layers
10009 draw_map_cflag(b, TheMaps[ layer_screen_index ], x1, y1);
10010 }
10011 }
10012
10013 if(rotation != 0) // rotate
10014 {
10015 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10016 script_drawing_commands.ReleaseSubBitmap(b);
10017 }
10018 }
10019
10020
10021 void draw_map_combotype(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10022 {
10023 BITMAP* square = create_bitmap_ex(8,16,16);
10024
10025 for(int32_t i(0); i < 176; ++i)
10026 {
10027 const int32_t x2 = ((i&15)<<4) + x;
10028 const int32_t y2 = (i&0xF0) + y;
10029 //Blit the palette index of the solidity value.
10030 clear_to_color(square,(combobuf[m.data[i]].type));
10031 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10032 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10033 }
10034 destroy_bitmap(square);
10035 }
10036
10037 void do_bmpdrawscreen_ctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10038 {
10039 //sdci[1]=layer
10040 //sdci[2]=map
10041 //sdci[3]=screen
10042 //sdci[4]=x
10043 //sdci[5]=y
10044 //sdci[6]=rotation
10045 //sdci[17] Bitmap Pointer
10046
10047 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
10048 if ( refbmp == NULL ) return;
10049
10050 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
10051
10052 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10053 int32_t scrn = sdci[3]/10000;
10054 int32_t x = sdci[4]/10000;
10055 int32_t y = sdci[5]/10000;
10056 int32_t x1 = x + xoffset;
10057 int32_t y1 = y + yoffset;
10058 int32_t rotation = sdci[6]/10000;
10059
10060 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10061
10062 if(index >= TheMaps.size())
10063 {
10064 al_trace("DrawScreen: invalid map or screen index. \n");
10065 return;
10066 }
10067
10068 const mapscr & m = TheMaps[index];
10069
10070
10071 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
10072 if ( refbmp == NULL ) return;
10073
10074 if(rotation != 0)
10075 b = script_drawing_commands.AquireSubBitmap(256, 176);
10076
10077 //draw layer 0
10078 draw_map_combotype(b, m, x1, y1);
10079
10080 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS))
10081 {
10082 for(int32_t i(0); i < 6; ++i)
10083 {
10084 if(m.layermap[i] == 0) continue;
10085
10086 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10087
10088 if(layer_screen_index >= TheMaps.size())
10089 continue;
10090
10091 //draw valid layers
10092 draw_map_combotype(b, TheMaps[ layer_screen_index ], x1, y1);
10093 }
10094 }
10095
10096 if(rotation != 0) // rotate
10097 {
10098 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10099 script_drawing_commands.ReleaseSubBitmap(b);
10100 }
10101 }
10102
10103
10104 void draw_map_comboiflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10105 {
10106 BITMAP* square = create_bitmap_ex(8,16,16);
10107
10108 for(int32_t i(0); i < 176; ++i)
10109 {
10110 const int32_t x2 = ((i&15)<<4) + x;
10111 const int32_t y2 = (i&0xF0) + y;
10112 //Blit the palette index of the solidity value.
10113 clear_to_color(square,(combobuf[m.data[i]].flag));
10114 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10115 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10116 }
10117 destroy_bitmap(square);
10118 }
10119
10120 void do_bmpdrawscreen_ciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10121 {
10122 //sdci[1]=layer
10123 //sdci[2]=map
10124 //sdci[3]=screen
10125 //sdci[4]=x
10126 //sdci[5]=y
10127 //sdci[6]=rotation
10128 //sdci[17] Bitmap Pointer
10129
10130 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
10131 if ( refbmp == NULL ) return;
10132
10133 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
10134
10135 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10136 int32_t scrn = sdci[3]/10000;
10137 int32_t x = sdci[4]/10000;
10138 int32_t y = sdci[5]/10000;
10139 int32_t x1 = x + xoffset;
10140 int32_t y1 = y + yoffset;
10141 int32_t rotation = sdci[6]/10000;
10142
10143 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10144
10145 if(index >= TheMaps.size())
10146 {
10147 al_trace("DrawScreen: invalid map or screen index. \n");
10148 return;
10149 }
10150
10151 const mapscr & m = TheMaps[index];
10152
10153
10154 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
10155 if ( refbmp == NULL ) return;
10156
10157 if(rotation != 0)
10158 b = script_drawing_commands.AquireSubBitmap(256, 176);
10159
10160 //draw layer 0
10161 draw_map_comboiflag(b, m, x1, y1);
10162
10163 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS))
10164 {
10165 for(int32_t i(0); i < 6; ++i)
10166 {
10167 if(m.layermap[i] == 0) continue;
10168
10169 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10170
10171 if(layer_screen_index >= TheMaps.size())
10172 continue;
10173
10174 //draw valid layers
10175 draw_map_comboiflag(b, TheMaps[ layer_screen_index ], x1, y1);
10176 }
10177 }
10178
10179 if(rotation != 0) // rotate
10180 {
10181 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10182 script_drawing_commands.ReleaseSubBitmap(b);
10183 }
10184 }
10185
10186 void do_drawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10187 {
10188 //sdci[1]=layer
10189 //sdci[2]=map
10190 //sdci[3]=screen
10191 //sdci[4]=layer
10192 //sdci[5]=x
10193 //sdci[6]=y
10194 //sdci[7]=rotation
10195 //sdci[8]=opacity
10196
10197 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10198 int32_t scrn = sdci[3]/10000;
10199 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10200 int32_t x = sdci[5]/10000;
10201 int32_t y = sdci[6]/10000;
10202 int32_t x1 = x + xoffset;
10203 int32_t y1 = y + yoffset;
10204 int32_t rotation = sdci[7]/10000;
10205 int32_t opacity = sdci[8]/10000;
10206
10207 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10208 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10209
10210 if(!m) //no need to log it.
10211 return;
10212
10213 if(index >= TheMaps.size())
10214 {
10215 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10216 return;
10217 }
10218
10219 const mapscr & l = *m;
10220
10221 BITMAP* b = bmp;
10222
10223 if(rotation != 0)
10224 b = script_drawing_commands.AquireSubBitmap(256, 176);
10225
10226
10227 const int32_t maxX = isOffScreen ? 512 : 256;
10228 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10229 bool transparent = opacity <= 128;
10230
10231 if(rotation != 0) // rotate
10232 {
10233 draw_mapscr(b, l, x1, y1, transparent);
10234
10235 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10236 script_drawing_commands.ReleaseSubBitmap(b);
10237 }
10238 else
10239 {
10240 for(int32_t i(0); i < 176; ++i)
10241 {
10242 const int32_t x2 = ((i&15)<<4) + x1;
10243 const int32_t y2 = (i&0xF0) + y1;
10244
10245 if(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY) //in clipping rect
10246 {
10247 const newcombo & c = combobuf[ l.data[i] ];
10248 const int32_t tile = combo_tile(c, x2, y2);
10249
10250 if(opacity < 128)
10251 {
10252 overcomboblocktranslucent(b, x2, y2, l.data[i], l.cset[i], 1, 1, 128);
10253
10254
10255 //overtiletranslucent16(b, tile, x2, y2, l.cset[i], c.flip, opacity);
10256 }
10257 else
10258 {
10259 overcomboblock(b, x2, y2, l.data[i], l.cset[i], 1, 1);
10260 //overtile16(b, tile, x2, y2, l.cset[i], c.flip);
10261 }
10262 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
10263 }
10264 }
10265 }
10266
10267 //putscr
10268 }
10269
10270
10271
10272 void do_drawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10273 {
10274 //sdci[1]=layer
10275 //sdci[2]=map
10276 //sdci[3]=screen
10277 //sdci[4]=x
10278 //sdci[5]=y
10279 //sdci[6]=rotation
10280
10281 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10282 int32_t scrn = sdci[3]/10000;
10283 int32_t x = sdci[4]/10000;
10284 int32_t y = sdci[5]/10000;
10285 int32_t x1 = x + xoffset;
10286 int32_t y1 = y + yoffset;
10287 int32_t rotation = sdci[6]/10000;
10288
10289 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10290
10291 if(index >= TheMaps.size())
10292 {
10293 al_trace("DrawScreen: invalid map or screen index. \n");
10294 return;
10295 }
10296
10297 const mapscr & m = TheMaps[index];
10298
10299
10300 BITMAP* b = bmp;
10301
10302 if(rotation != 0)
10303 b = script_drawing_commands.AquireSubBitmap(256, 176);
10304
10305 //draw layer 0
10306 draw_mapscr(b, m, x1, y1, false);
10307
10308 for(int32_t i(0); i < 6; ++i)
10309 {
10310 if(m.layermap[i] == 0) continue;
10311
10312 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10313
10314 if(layer_screen_index >= TheMaps.size())
10315 continue;
10316
10317 bool trans = m.layeropacity[i] == 128;
10318
10319 //draw valid layers
10320 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
10321 }
10322
10323 if(rotation != 0) // rotate
10324 {
10325 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10326 script_drawing_commands.ReleaseSubBitmap(b);
10327 }
10328 }
10329
10330
10331 21 void do_bmpdrawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10332 {
10333 //sdci[1]=layer
10334 //sdci[2]=map
10335 //sdci[3]=screen
10336 //sdci[4]=layer
10337 //sdci[5]=x
10338 //sdci[6]=y
10339 //sdci[7]=rotation
10340 //[8] noclip
10341 //sdci[9]=opacity
10342 //sdci[17] Bitmap Pointer
10343
10344 21 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
10345
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if ( refbmp == NULL ) return;
10346
10347 21 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10348 21 int32_t scrn = sdci[3]/10000;
10349 21 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10350 21 int32_t x = sdci[5]/10000;
10351 21 int32_t y = sdci[6]/10000;
10352 21 int32_t rotation = sdci[7]/10000;
10353
10354 21 byte noclip = 0;//(sdci[8]!=0);
10355 21 int32_t opacity = sdci[8]/10000;
10356 //zprint2("Running bmp->DrawLayer(%d, %d, %d, %d, %d, %d, %d, %d)\n", sdci[1]/10000, map, scrn, sourceLayer, x, y, rotation, opacity);
10357 21 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10358 21 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10359
10360
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 6 times.
21 if(!m) //no need to log it.
10361 6 return;
10362
10363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if(index >= TheMaps.size())
10364 {
10365 Z_scripterrlog("DrawLayer: invalid map index \"%i\". Map count is %d.\n", index, TheMaps.size());
10366 return;
10367 }
10368
10369 15 const mapscr & l = *m;
10370
10371 15 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
10372
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if ( refbmp == NULL ) return;
10373
2/4
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
15 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
10374
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if(rotation != 0)
10375 b = script_drawing_commands.AquireSubBitmap(256, 176);
10376
10377
10378 15 const int32_t maxX = isOffScreen ? 512 : 256;
10379
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10380 15 bool transparent = opacity <= 128;
10381
10382
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if(rotation != 0) // rotate
10383 {
10384 draw_mapscr(b, l, x, y, transparent);
10385
10386 rotate_sprite(refbmp, b, x, y, degrees_to_fixed(rotation));
10387 script_drawing_commands.ReleaseSubBitmap(b);
10388 }
10389 else
10390 {
10391
2/2
✓ Branch 0 taken 2640 times.
✓ Branch 1 taken 15 times.
2655 for(int32_t i(0); i < 176; ++i)
10392 {
10393 2640 const int32_t x2 = ((i&15)<<4) + x;
10394 2640 const int32_t y2 = (i&0xF0) + y;
10395
10396 //if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10397 {
10398 2640 const newcombo & c = combobuf[ l.data[i] ];
10399 2640 const int32_t tile = combo_tile(c, x2, y2);
10400
10401
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2640 times.
2640 if(opacity < 128)
10402 overtiletranslucent16(refbmp, tile, x2, y2, l.cset[i], c.flip, opacity);
10403 else
10404 2640 overtile16(refbmp, tile, x2, y2, l.cset[i], c.flip);
10405
10406 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
10407 }
10408 2640 }
10409 }
10410
10411 //putscr
10412 21 }
10413
10414
10415
10416 68 void do_bmpdrawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10417 {
10418 //sdci[1]=layer
10419 //sdci[2]=map
10420 //sdci[3]=screen
10421 //sdci[4]=x
10422 //sdci[5]=y
10423 //sdci[6]=rotation
10424 //sdci[17] Bitmap Pointer
10425
10426 68 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
10427
1/2
✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
68 if ( refbmp == NULL ) return;
10428
10429
2/4
✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 68 times.
68 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
10430
10431 68 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10432 68 int32_t scrn = sdci[3]/10000;
10433 68 int32_t x = sdci[4]/10000;
10434 68 int32_t y = sdci[5]/10000;
10435 68 int32_t x1 = x + xoffset;
10436 68 int32_t y1 = y + yoffset;
10437 68 int32_t rotation = sdci[6]/10000;
10438
10439 68 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10440
10441
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
68 if(index >= TheMaps.size())
10442 {
10443 al_trace("DrawScreen: invalid map or screen index. \n");
10444 return;
10445 }
10446
10447 68 const mapscr & m = TheMaps[index];
10448
10449
10450 68 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
10451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
68 if ( refbmp == NULL ) return;
10452
10453
1/2
✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
68 if(rotation != 0)
10454 b = script_drawing_commands.AquireSubBitmap(256, 176);
10455
10456 //draw layer 0
10457 68 draw_mapscr(b, m, x1, y1, false);
10458
10459
2/2
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 408 times.
476 for(int32_t i(0); i < 6; ++i)
10460 {
10461
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 338 times.
408 if(m.layermap[i] == 0) continue;
10462
10463 70 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10464
10465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 if(layer_screen_index >= TheMaps.size())
10466 continue;
10467
10468 70 bool trans = m.layeropacity[i] == 128;
10469
10470 //draw valid layers
10471 70 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
10472 70 }
10473
10474
1/2
✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
68 if(rotation != 0) // rotate
10475 {
10476 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10477 script_drawing_commands.ReleaseSubBitmap(b);
10478 }
10479 68 }
10480
10481 void do_bmpdrawlayersolidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10482 {
10483 //sdci[1]=layer
10484 //sdci[2]=map
10485 //sdci[3]=screen
10486 //sdci[4]=layer
10487 //sdci[5]=x
10488 //sdci[6]=y
10489 //sdci[7]=rotation
10490 //sdci[8]=bool noclip
10491 //sdci[9] == opacity
10492
10493 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10494 int32_t scrn = sdci[3]/10000;
10495 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10496 int32_t x = sdci[5]/10000;
10497 int32_t y = sdci[6]/10000;
10498 int32_t x1 = x + xoffset;
10499 int32_t y1 = y + yoffset;
10500 int32_t rotation = sdci[7]/10000;
10501 byte noclip = (sdci[8]!=0);
10502 int32_t opacity = sdci[9]/10000;
10503
10504 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10505 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10506
10507 if(!m) //no need to log it.
10508 return;
10509
10510 if(index >= TheMaps.size())
10511 {
10512 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10513 return;
10514 }
10515
10516 const mapscr & l = *m;
10517
10518 BITMAP* b = bmp;
10519
10520 if(rotation != 0)
10521 b = script_drawing_commands.AquireSubBitmap(256, 176);
10522
10523
10524 const int32_t maxX = isOffScreen ? 512 : 256;
10525 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10526 bool transparent = opacity <= 128;
10527
10528 if(rotation != 0) // rotate
10529 {
10530 draw_map_solid(b, l, x1, y1);
10531
10532 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10533 script_drawing_commands.ReleaseSubBitmap(b);
10534 }
10535 else
10536 {
10537 BITMAP* square = create_bitmap_ex(8,16,16);
10538 BITMAP* subsquare = create_bitmap_ex(8,16,16);
10539 clear_to_color(subsquare,1);
10540 for(int32_t i(0); i < 176; ++i)
10541 {
10542 const int32_t x2 = ((i&15)<<4) + x1;
10543 const int32_t y2 = (i&0xF0) + y1;
10544
10545 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10546 {
10547 int32_t sol = (combobuf[l.data[i]].walk);
10548
10549 if ( sol & 1 )
10550 {
10551 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
10552 }
10553 if ( sol & 2 )
10554 {
10555 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
10556 }
10557 if ( sol & 4 )
10558 {
10559 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
10560 }
10561 if ( sol &8 ) {
10562 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
10563 }
10564
10565 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10566 }
10567 }
10568 destroy_bitmap(square);
10569 destroy_bitmap(subsquare);
10570 }
10571
10572 //putscr
10573 }
10574
10575 void do_bmpdrawlayersolidityr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10576 {
10577 //sdci[1]=layer
10578 //sdci[2]=map
10579 //sdci[3]=screen
10580 //sdci[4]=layer
10581 //sdci[5]=x
10582 //sdci[6]=y
10583 //sdci[7]=rotation
10584 //[8] noclip
10585 //sdci[9]=opacity
10586
10587
10588 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10589 int32_t scrn = sdci[3]/10000;
10590 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10591 int32_t x = sdci[5]/10000;
10592 int32_t y = sdci[6]/10000;
10593 int32_t x1 = x + xoffset;
10594 int32_t y1 = y + yoffset;
10595 int32_t rotation = sdci[7]/10000;
10596 byte noclip = (sdci[8]!=0);
10597 int32_t opacity = sdci[9]/10000;
10598
10599 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10600 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10601
10602 if(!m) //no need to log it.
10603 return;
10604
10605 if(index >= TheMaps.size())
10606 {
10607 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10608 return;
10609 }
10610
10611 const mapscr & l = *m;
10612
10613 BITMAP* b = bmp;
10614
10615 if(rotation != 0)
10616 b = script_drawing_commands.AquireSubBitmap(256, 176);
10617
10618
10619 const int32_t maxX = isOffScreen ? 512 : 256;
10620 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10621 bool transparent = opacity <= 128;
10622
10623 if(rotation != 0) // rotate
10624 {
10625 draw_map_solidity(b, l, x1, y1);
10626
10627 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10628 script_drawing_commands.ReleaseSubBitmap(b);
10629 }
10630 else
10631 {
10632 BITMAP* square = create_bitmap_ex(8,16,16);
10633 for(int32_t i(0); i < 176; ++i)
10634 {
10635 const int32_t x2 = ((i&15)<<4) + x1;
10636 const int32_t y2 = (i&0xF0) + y1;
10637
10638 if(noclip && (x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10639 {
10640 clear_to_color(square,(combobuf[l.data[i]].walk&15));
10641 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10642 }
10643 }
10644 destroy_bitmap(square);
10645 }
10646
10647 //putscr
10648 }
10649
10650 void do_bmpdrawlayercflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10651 {
10652 //sdci[1]=layer
10653 //sdci[2]=map
10654 //sdci[3]=screen
10655 //sdci[4]=layer
10656 //sdci[5]=x
10657 //sdci[6]=y
10658 //sdci[7]=rotation
10659 //[8] noclip
10660 //sdci[9]=opacity
10661
10662
10663 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10664 int32_t scrn = sdci[3]/10000;
10665 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10666 int32_t x = sdci[5]/10000;
10667 int32_t y = sdci[6]/10000;
10668 int32_t x1 = x + xoffset;
10669 int32_t y1 = y + yoffset;
10670 int32_t rotation = sdci[7]/10000;
10671
10672 byte noclip = (sdci[8]!=0);
10673 int32_t opacity = sdci[9]/10000;
10674
10675 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10676 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10677
10678 if(!m) //no need to log it.
10679 return;
10680
10681 if(index >= TheMaps.size())
10682 {
10683 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10684 return;
10685 }
10686
10687 const mapscr & l = *m;
10688
10689 BITMAP* b = bmp;
10690
10691 if(rotation != 0)
10692 b = script_drawing_commands.AquireSubBitmap(256, 176);
10693
10694
10695 const int32_t maxX = isOffScreen ? 512 : 256;
10696 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10697 bool transparent = opacity <= 128;
10698
10699 if(rotation != 0) // rotate
10700 {
10701 draw_map_cflag(b, l, x1, y1);
10702
10703 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10704 script_drawing_commands.ReleaseSubBitmap(b);
10705 }
10706 else
10707 {
10708 BITMAP* square = create_bitmap_ex(8,16,16);
10709 for(int32_t i(0); i < 176; ++i)
10710 {
10711 const int32_t x2 = ((i&15)<<4) + x1;
10712 const int32_t y2 = (i&0xF0) + y1;
10713
10714 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10715 {
10716 clear_to_color(square,l.sflag[i]);
10717 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10718 }
10719 }
10720 destroy_bitmap(square);
10721 }
10722
10723 //putscr
10724 }
10725
10726 void do_bmpdrawlayerctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10727 {
10728 //sdci[1]=layer
10729 //sdci[2]=map
10730 //sdci[3]=screen
10731 //sdci[4]=layer
10732 //sdci[5]=x
10733 //sdci[6]=y
10734 //sdci[7]=rotation
10735 //[8] noclip
10736 //sdci[9]=opacity
10737
10738 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10739 int32_t scrn = sdci[3]/10000;
10740 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10741 int32_t x = sdci[5]/10000;
10742 int32_t y = sdci[6]/10000;
10743 int32_t x1 = x + xoffset;
10744 int32_t y1 = y + yoffset;
10745 int32_t rotation = sdci[7]/10000;
10746
10747 byte noclip = (sdci[8]!=0);
10748 int32_t opacity = sdci[9]/10000;
10749 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10750 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10751
10752 if(!m) //no need to log it.
10753 return;
10754
10755 if(index >= TheMaps.size())
10756 {
10757 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10758 return;
10759 }
10760
10761 const mapscr & l = *m;
10762
10763 BITMAP* b = bmp;
10764
10765 if(rotation != 0)
10766 b = script_drawing_commands.AquireSubBitmap(256, 176);
10767
10768
10769 const int32_t maxX = isOffScreen ? 512 : 256;
10770 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10771 bool transparent = opacity <= 128;
10772
10773 if(rotation != 0) // rotate
10774 {
10775 draw_map_combotype(b, l, x1, y1);
10776
10777 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10778 script_drawing_commands.ReleaseSubBitmap(b);
10779 }
10780 else
10781 {
10782 BITMAP* square = create_bitmap_ex(8,16,16);
10783 for(int32_t i(0); i < 176; ++i)
10784 {
10785 const int32_t x2 = ((i&15)<<4) + x1;
10786 const int32_t y2 = (i&0xF0) + y1;
10787
10788 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10789 {
10790 clear_to_color(square,(combobuf[l.data[i]].type));
10791 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10792 }
10793 }
10794 destroy_bitmap(square);
10795 }
10796
10797 //putscr
10798 }
10799
10800 void do_bmpdrawlayerciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10801 {
10802 //sdci[1]=layer
10803 //sdci[2]=map
10804 //sdci[3]=screen
10805 //sdci[4]=layer
10806 //sdci[5]=x
10807 //sdci[6]=y
10808 //sdci[7]=rotation
10809 //[8] noclip
10810 //sdci[9]=opacity
10811
10812 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10813 int32_t scrn = sdci[3]/10000;
10814 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10815 int32_t x = sdci[5]/10000;
10816 int32_t y = sdci[6]/10000;
10817 int32_t x1 = x + xoffset;
10818 int32_t y1 = y + yoffset;
10819 int32_t rotation = sdci[7]/10000;
10820 byte noclip = (sdci[8]!=0);
10821 int32_t opacity = sdci[9]/10000;
10822
10823 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10824 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10825
10826 if(!m) //no need to log it.
10827 return;
10828
10829 if(index >= TheMaps.size())
10830 {
10831 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10832 return;
10833 }
10834
10835 const mapscr & l = *m;
10836
10837 BITMAP* b = bmp;
10838
10839 if(rotation != 0)
10840 b = script_drawing_commands.AquireSubBitmap(256, 176);
10841
10842
10843 const int32_t maxX = isOffScreen ? 512 : 256;
10844 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10845 bool transparent = opacity <= 128;
10846
10847 if(rotation != 0) // rotate
10848 {
10849 draw_map_comboiflag(b, l, x1, y1);
10850
10851 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10852 script_drawing_commands.ReleaseSubBitmap(b);
10853 }
10854 else
10855 {
10856 BITMAP* square = create_bitmap_ex(8,16,16);
10857 for(int32_t i(0); i < 176; ++i)
10858 {
10859 const int32_t x2 = ((i&15)<<4) + x1;
10860 const int32_t y2 = (i&0xF0) + y1;
10861
10862 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10863 {
10864 clear_to_color(square,(combobuf[l.data[i]].flag));
10865 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10866 }
10867 }
10868 destroy_bitmap(square);
10869 }
10870
10871 //putscr
10872 }
10873
10874
10875
10876 /////////////////////////////////////////////////////////
10877 // do primitives
10878 ////////////////////////////////////////////////////////
10879
10880 643711 void do_primitives(BITMAP *targetBitmap, int32_t type, mapscr* theScreen, int32_t xoff, int32_t yoff)
10881 {
10882 643711 color_map = &trans_table2;
10883
10884 //was this next variable ever used? -- DN
10885 //bool drawsubscr=false;
10886
10887
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 643711 times.
643711 if(type > 7)
10888 return;
10889
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 643711 times.
643711 if(theScreen->hidescriptlayers & (1<<type))
10890 return; //Script draws hidden for this layer
10891 //--script_drawing_commands[][] reference--
10892 //[][0]: type
10893 //[][1-16]: defined by type
10894 //[][17]: unused
10895 //[][18]: rendertarget
10896 //[][19]: unused
10897
10898 // Trying to match the old behavior exactly...
10899
2/2
✓ Branch 0 taken 364730 times.
✓ Branch 1 taken 278981 times.
643711 const bool brokenOffset= ( (get_bit(extra_rules, er_BITMAPOFFSET)!=0) || (get_bit(quest_rules,qr_BITMAPOFFSETFIX)!=0) );
10900
10901 643711 bool isTargetOffScreenBmp = false;
10902 643711 const int32_t type_mul_10000 = type * 10000;
10903 643711 const int32_t numDrawCommandsToProcess = script_drawing_commands.Count();
10904 643711 FFCore.numscriptdraws = numDrawCommandsToProcess;
10905 643711 int32_t xoffset=xoff, yoffset=yoff;
10906
2/2
✓ Branch 0 taken 1078560 times.
✓ Branch 1 taken 643711 times.
1722271 for(int32_t i(0); i < numDrawCommandsToProcess; ++i)
10907 {
10908
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1078560 times.
1078560 if(!brokenOffset)
10909 {
10910 1078560 xoffset = 0;
10911 1078560 yoffset = 0;
10912 1078560 }
10913 1078560 int32_t *sdci = &script_drawing_commands[i][0];
10914
10915
2/2
✓ Branch 0 taken 943740 times.
✓ Branch 1 taken 134820 times.
1078560 if(sdci[1] != type_mul_10000)
10916 943740 continue;
10917 // get the correct render target, if set.
10918 134820 BITMAP *bmp = zscriptDrawingRenderTarget->GetTargetBitmap(sdci[18]);
10919
10920
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 134820 times.
134820 if(!bmp)
10921 {
10922 // draw to screen with subscreen offset
10923
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 134820 times.
134820 if(!brokenOffset)
10924 {
10925 134820 xoffset = xoff;
10926 134820 yoffset = yoff;
10927 134820 }
10928 134820 bmp = targetBitmap;
10929 134820 }
10930 else
10931 {
10932 //not drawing to screen, so no subscreen offset
10933 if(brokenOffset)
10934 {
10935 xoffset = 0;
10936 yoffset = 0;
10937 }
10938 isTargetOffScreenBmp = true;
10939 }
10940
10941
18/82
✗ Branch 0 not taken.
✓ Branch 1 taken 34260 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 4893 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 8328 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 34286 times.
✓ Branch 18 taken 4233 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1902 times.
✓ Branch 22 taken 18817 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 12 times.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 264 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 3 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 4630 times.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✓ Branch 56 taken 21 times.
✓ Branch 57 taken 68 times.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✓ Branch 63 taken 6787 times.
✗ Branch 64 not taken.
✓ Branch 65 taken 3 times.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✓ Branch 68 taken 7473 times.
✓ Branch 69 taken 190 times.
✓ Branch 70 taken 8650 times.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
134820 switch(sdci[0])
10942 {
10943 case RECTR:
10944 {
10945 34260 do_rectr(bmp, sdci, xoffset, yoffset);
10946 }
10947 34260 break;
10948 case FRAMER:
10949 {
10950 do_framer(bmp, sdci, xoffset, yoffset);
10951 }
10952 break;
10953
10954
10955 case CIRCLER:
10956 {
10957 do_circler(bmp, sdci, xoffset, yoffset);
10958 }
10959 break;
10960
10961 case ARCR:
10962 {
10963 do_arcr(bmp, sdci, xoffset, yoffset);
10964 }
10965 break;
10966
10967 case ELLIPSER:
10968 {
10969 do_ellipser(bmp, sdci, xoffset, yoffset);
10970 }
10971 break;
10972
10973 case LINER:
10974 {
10975 do_liner(bmp, sdci, xoffset, yoffset);
10976 }
10977 break;
10978
10979 case SPLINER:
10980 {
10981 do_spliner(bmp, sdci, xoffset, yoffset);
10982 }
10983 break;
10984
10985 case PUTPIXELR:
10986 {
10987 do_putpixelr(bmp, sdci, xoffset, yoffset);
10988 }
10989 break;
10990 case PIXELARRAYR:
10991 {
10992 //Z_scripterrlog("Reached case PIXELARRAYR\n");
10993 do_putpixelsr(bmp, i, sdci, xoffset, yoffset);
10994 }
10995 break;
10996
10997 case TILEARRAYR:
10998 {
10999 //Z_scripterrlog("Reached case PIXELARRAYR\n");
11000 do_fasttilesr(bmp, i, sdci, xoffset, yoffset);
11001 }
11002 break;
11003
11004 case LINESARRAY:
11005 {
11006 //Z_scripterrlog("Reached case PIXELARRAYR\n");
11007 do_linesr(bmp, i, sdci, xoffset, yoffset);
11008 }
11009 break;
11010
11011 case COMBOARRAYR:
11012 {
11013 //Z_scripterrlog("Reached case PIXELARRAYR\n");
11014 do_fastcombosr(bmp, i, sdci, xoffset, yoffset);
11015 }
11016 break;
11017
11018
11019
11020 case DRAWTILER:
11021 {
11022 4893 do_drawtiler(bmp, sdci, xoffset, yoffset);
11023 }
11024 4893 break;
11025
11026 case DRAWTILECLOAKEDR:
11027 {
11028 do_drawtilecloakedr(bmp, sdci, xoffset, yoffset);
11029 }
11030 break;
11031
11032 case DRAWCOMBOR:
11033 {
11034 8328 do_drawcombor(bmp, sdci, xoffset, yoffset);
11035 }
11036 8328 break;
11037
11038 case DRAWCOMBOCLOAKEDR:
11039 {
11040 do_drawcombocloakedr(bmp, sdci, xoffset, yoffset);
11041 }
11042 break;
11043
11044 case FASTTILER:
11045 {
11046 34286 do_fasttiler(bmp, sdci, xoffset, yoffset);
11047 }
11048 34286 break;
11049
11050 case FASTCOMBOR:
11051 {
11052 4233 do_fastcombor(bmp, sdci, xoffset, yoffset);
11053 }
11054 4233 break;
11055
11056 case DRAWCHARR:
11057 {
11058 do_drawcharr(bmp, sdci, xoffset, yoffset);
11059 }
11060 break;
11061
11062 case DRAWINTR:
11063 {
11064 do_drawintr(bmp, sdci, xoffset, yoffset);
11065 }
11066 break;
11067
11068 case DRAWSTRINGR:
11069 {
11070 1902 do_drawstringr(bmp, i, sdci, xoffset, yoffset);
11071 }
11072 1902 break;
11073
11074 case DRAWSTRINGR2:
11075 {
11076 18817 do_drawstringr2(bmp, i, sdci, xoffset, yoffset);
11077 }
11078 18817 break;
11079
11080 case QUADR:
11081 {
11082 do_drawquadr(bmp, sdci, xoffset, yoffset);
11083 }
11084 break;
11085
11086 case QUAD3DR:
11087 {
11088 do_drawquad3dr(bmp, i, sdci, xoffset, yoffset);
11089 }
11090 break;
11091
11092 case TRIANGLER:
11093 {
11094 do_drawtriangler(bmp, sdci, xoffset, yoffset);
11095 }
11096 break;
11097
11098 case TRIANGLE3DR:
11099 {
11100 do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset);
11101 }
11102 break;
11103
11104 case POLYGONR:
11105 {
11106 do_polygonr(bmp, i, sdci, xoffset, yoffset);
11107 }
11108 break;
11109
11110
11111 case BITMAPR:
11112 {
11113 do_drawbitmapr(bmp, sdci, xoffset, yoffset);
11114 }
11115 break;
11116
11117 case BITMAPEXR:
11118 {
11119 do_drawbitmapexr(bmp, sdci, xoffset, yoffset);
11120 }
11121 break;
11122
11123 case DRAWLAYERR:
11124 {
11125 do_drawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
11126 }
11127 break;
11128
11129 case DRAWSCREENR:
11130 {
11131 do_drawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
11132 }
11133 break;
11134
11135 12 case BMPRECTR: bmp_do_rectr(bmp, sdci, xoffset, yoffset); break;
11136 case BMPFRAMER: bmp_do_framer(bmp, sdci, xoffset, yoffset); break;
11137 case BMPCIRCLER: bmp_do_circler(bmp, sdci, xoffset, yoffset); break;
11138 case BMPARCR: bmp_do_arcr(bmp, sdci, xoffset, yoffset); break;
11139 case BMPELLIPSER: bmp_do_ellipser(bmp, sdci, xoffset, yoffset); break;
11140 case BMPLINER: bmp_do_liner(bmp, sdci, xoffset, yoffset); break;
11141 case BMPSPLINER: bmp_do_spliner(bmp, sdci, xoffset, yoffset); break;
11142 case BMPPUTPIXELR: bmp_do_putpixelr(bmp, sdci, xoffset, yoffset); break;
11143 264 case BMPDRAWTILER: bmp_do_drawtiler(bmp, sdci, xoffset, yoffset); break;
11144 case BMPDRAWTILECLOAKEDR: bmp_do_drawtilecloakedr(bmp, sdci, xoffset, yoffset); break;
11145 3 case BMPDRAWCOMBOR: bmp_do_drawcombor(bmp, sdci, xoffset, yoffset); break;
11146 case BMPDRAWCOMBOCLOAKEDR: bmp_do_drawcombocloakedr(bmp, sdci, xoffset, yoffset); break;
11147 4630 case BMPFASTTILER: bmp_do_fasttiler(bmp, sdci, xoffset, yoffset); break;
11148 case BMPFASTCOMBOR: bmp_do_fastcombor(bmp, sdci, xoffset, yoffset); break;
11149 case BMPDRAWCHARR: bmp_do_drawcharr(bmp, sdci, xoffset, yoffset); break;
11150 case BMPDRAWINTR: bmp_do_drawintr(bmp, sdci, xoffset, yoffset); break;
11151 case BMPDRAWSTRINGR: bmp_do_drawstringr(bmp, i, sdci, xoffset, yoffset); break;
11152 case BMPDRAWSTRINGR2: bmp_do_drawstringr2(bmp, i, sdci, xoffset, yoffset); break;
11153 case BMPQUADR: bmp_do_drawquadr(bmp, sdci, xoffset, yoffset); break;
11154 case BMPQUAD3DR: bmp_do_drawquad3dr(bmp, i, sdci, xoffset, yoffset); break;
11155
11156 case BITMAPGETPIXEL: bmp_do_getpixelr(bmp, sdci, xoffset, yoffset); break;
11157 case BMPTRIANGLER: bmp_do_drawtriangler(bmp, sdci, xoffset, yoffset); break;
11158 case BMPTRIANGLE3DR: bmp_do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset); break;
11159 case BMPPOLYGONR: bmp_do_polygonr(bmp, i, sdci, xoffset, yoffset); break;
11160 21 case BMPDRAWLAYERR: do_bmpdrawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11161 68 case BMPDRAWSCREENR: do_bmpdrawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11162 case BMPDRAWSCREENSOLIDR: do_bmpdrawscreen_solidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11163 case BMPDRAWSCREENSOLID2R: do_bmpdrawscreen_solidr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11164 case BMPDRAWSCREENCOMBOFR: do_bmpdrawscreen_cflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11165 case BMPDRAWSCREENCOMBOIR: do_bmpdrawscreen_ciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11166 case BMPDRAWSCREENCOMBOTR: do_bmpdrawscreen_ctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11167 6787 case BMPBLIT: bmp_do_drawbitmapexr(bmp, sdci, xoffset, yoffset); break;
11168 case BMPMODE7: bmp_do_mode7r(bmp, sdci, xoffset, yoffset); break;
11169 3 case BMPBLITTO: bmp_do_blittor(bmp, sdci, xoffset, yoffset); break;
11170 case READBITMAP: bmp_do_readr(bmp, i, sdci, xoffset, yoffset); break;
11171 case WRITEBITMAP: bmp_do_writer(bmp, i, sdci, xoffset, yoffset); break;
11172 7473 case CLEARBITMAP: bmp_do_clearr(bmp, sdci, xoffset, yoffset); break;
11173 190 case BITMAPCLEARTOCOLOR: bmp_do_clearcolorr(bmp, sdci, xoffset, yoffset); break;
11174 8650 case REGENERATEBITMAP: bmp_do_regenr(bmp, sdci, xoffset, yoffset); break;
11175
11176 case BMPDRAWLAYERSOLIDR: do_bmpdrawlayersolidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11177 case BMPDRAWLAYERCFLAGR: do_bmpdrawlayercflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11178 case BMPDRAWLAYERCTYPER: do_bmpdrawlayerctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11179 case BMPDRAWLAYERCIFLAGR: do_bmpdrawlayerciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11180 case BMPDRAWLAYERSOLIDITYR: do_bmpdrawlayersolidityr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11181 case BMPWRITETILE: do_bmpwritetile(bmp, sdci, xoffset, yoffset); break;
11182 case BMPDITHER: do_bmpdither(bmp, sdci, xoffset, yoffset); break;
11183 case BMPREPLCOLOR: do_bmpreplcol(bmp, sdci, xoffset, yoffset); break;
11184 case BMPSHIFTCOLOR: do_bmpshiftcol(bmp, sdci, xoffset, yoffset); break;
11185 case BMPMASKDRAW: do_bmpmaskdraw(bmp, sdci, xoffset, yoffset); break;
11186 case BMPMASKBLIT: do_bmpmaskblit(bmp, sdci, xoffset, yoffset); break;
11187 }
11188 134820 }
11189
11190
11191 643711 color_map=&trans_table;
11192 643711 }
11193
11194 76443 void CScriptDrawingCommands::Clear()
11195 {
11196 76443 scb.update();
11197
2/2
✓ Branch 0 taken 72609 times.
✓ Branch 1 taken 3834 times.
76443 if(commands.empty())
11198 72609 return;
11199
11200 //only clear what was used.
11201 3834 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
11202 3834 count = 0;
11203
11204 3834 draw_container.Clear();
11205 76443 }
11206 CScriptDrawingCommands* CScriptDrawingCommands::pop_commands()
11207 {
11208 CScriptDrawingCommands* ret = new CScriptDrawingCommands();
11209 if(commands.empty())
11210 return ret;
11211 ret->push_commands(this, false);
11212
11213 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
11214 count = 0;
11215
11216 draw_container.Clear();
11217 return ret;
11218 }
11219 void CScriptDrawingCommands::push_commands(CScriptDrawingCommands* other, bool del)
11220 {
11221 commands.insert(commands.end(), other->commands.begin(), other->commands.end());
11222 count += other->count;
11223 if(del) delete other;
11224 }
11225
11226 256 void do_script_draws(BITMAP *targetBitmap, mapscr* theScreen, int32_t xoff, int32_t yoff, bool hideLayer7)
11227 {
11228
1/2
✓ Branch 0 taken 256 times.
✗ Branch 1 not taken.
256 if(XOR(theScreen->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, theScreen, xoff, yoff);
11229
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 255 times.
256 if(XOR(theScreen->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, theScreen, xoff, yoff);
11230 256 do_primitives(targetBitmap, 0, theScreen, xoff, yoff);
11231 256 do_primitives(targetBitmap, 1, theScreen, xoff, yoff);
11232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 256 times.
256 if(!XOR(theScreen->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, theScreen, xoff, yoff);
11233
2/2
✓ Branch 0 taken 255 times.
✓ Branch 1 taken 1 times.
256 if(!XOR(theScreen->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, theScreen, xoff, yoff);
11234 256 do_primitives(targetBitmap, 4, theScreen, xoff, yoff);
11235 256 do_primitives(targetBitmap, 5, theScreen, xoff, yoff);
11236 256 do_primitives(targetBitmap, 6, theScreen, xoff, yoff);
11237
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 256 times.
256 if(!hideLayer7) do_primitives(targetBitmap, 7, theScreen, xoff, yoff);
11238 256 }
11239